E_Schyler
E_Schyler

Reputation: 117

sorting columns from lowest to highest values (i.e. 1, 2, 3 etc, not 1, 10, 11...2, 20, 21... etc)

I have a dataset with 50 thousand rows that I want to sort according the the values in one of the columns. The numbers in the column go from 1-30, and when I do the following

 data=data[order(data$columnname),]

it gets sorted so that the order of the columns is like this

1, 10, 11 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 4, 5, 6, 7, 8, 9

how could I sort it so that it is like this

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30

Upvotes: 2

Views: 1628

Answers (1)

Otto_K
Otto_K

Reputation: 341

For me it seems, that your format is not numeric. Try this:

data$columnname<-as.numeric(data$columnname)
data=data[order(data$columnname),]

Upvotes: 2

Related Questions