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 559 views

## 1 answer to this question.

```> 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

• 52,360 points

+1 vote

## How to sort a data frame by columns in R?

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

## 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

+1 vote

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

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

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

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

## By using dpylr package sum of multiple columns

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

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

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

## In a dpylr pipline how to use sample and seq?

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

## How to create a list of Data frames?

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