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
• 18,520 points
754 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
• 52,350 points

Related Questions In Data Analytics

+1 vote
2 answers

How to sort a data frame by columns in R?

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

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
1,818 views
0 votes
2 answers

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

The function match works on vectors : x <- sample(1:10) x # ...READ MORE

answered Dec 12, 2020 in Data Analytics by Rajiv
• 8,870 points
56,643 views
+1 vote
2 answers

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
82,379 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 24, 2018 in Data Analytics by zombie
• 3,790 points
1,818 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
2,256 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
1,929 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

edited Jun 9, 2020 by Gitika 1,186 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
1,348 views
+2 votes
2 answers
0 votes
2 answers

Installing MXNet for R in Windows System

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

answered Dec 4, 2018 in Data Analytics by Kalgi
• 52,350 points
2,437 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP