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
• 16,220 points
40 views

1 answer to this question.

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
• 42,280 points

Related Questions In Data Analytics

0 votes
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21 in Data Analytics by anonymous
• 31,840 points
146 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
751 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
1,878 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
42 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,720 points
113 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,720 points
157 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,720 points
82 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,720 points
99 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
• 42,280 points
407 views