Sort function in R

0 votes
I am using the sort function on a particular column to rank hospitals based on a specific outcome.

The data ranges in value from 8.0 to 20.0.

However, when I use the sort function, instead of the lowest value appearing first, the data will be sorted with 10.0 first, followed by all data beginning with a 1, and will end with the lowest data (8.0, 8.1, 8.2).
Nov 5, 2018 in Data Analytics by Hannah
• 14,080 points
21 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
> set.seed(1)
> s <- sample(seq(8, 20, by = 0.1), 20, TRUE)
> sort(s)
 [1]  8.7 10.1 10.4 10.4 11.2 12.5 12.5 12.6 14.0 14.9 15.6 15.9
[13] 16.3 16.6 17.3 17.4 18.8 18.9 19.4 20.0
> sort(as.character(s))
 [1] "10.1" "10.4" "10.4" "11.2" "12.5" "12.5" "12.6" "14"  
 [9] "14.9" "15.6" "15.9" "16.3" "16.6" "17.3" "17.4" "18.8"
[17] "18.9" "19.4" "20"   "8.7" 

Try something like this

answered Nov 5, 2018 by Kalgi
• 35,720 points

Related Questions In Data Analytics

0 votes
1 answer

How to sort a data frame by columns in R?

You can just use the order function ...READ MORE

answered Apr 10, 2018 in Data Analytics by darklord
• 6,140 points
49 views
0 votes
1 answer

R function for finding the index of an element in a vector?

Yes, we can find the index of ...READ MORE

answered Apr 13, 2018 in Data Analytics by zombie
• 3,690 points
65 views
0 votes
1 answer

Which function can I use to clear the console in R and RStudio ?

Description                   Windows & Linux           Mac Clear console                      Ctrl+L ...READ MORE

answered Apr 17, 2018 in Data Analytics by anonymous
626 views
0 votes
1 answer

Why should I use set.seed function() in R?

set.seed(seed) Set the seed of R‘s random number ...READ MORE

answered Apr 23, 2018 in Data Analytics by zombie
• 3,690 points
10 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,700 points
23 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,700 points
60 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,700 points
35 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,700 points
32 views
0 votes
2 answers

Installing MXNet for R in Windows System

You can install it for python in ...READ MORE

answered Dec 3, 2018 in Data Analytics by Kalgi
• 35,720 points
174 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.