I think this should be really simple, but I cannot find a way to do this.
I want to reorder a dataframe based on a factor. All the answers I can find so far provide logical sorting, but this is arbitrary, and a mixture of numbers and letters. Maybe it's a problem because it is a factor
not a vector
? But none of the answers for vectors seem to work either.
Any suggestions would be really appreciated!
Example data (note; this data is just for this question, in my real code the dataframe is the output of some other calculations and so I can't just alter the names to something sensible right at the start)
DATA<- data.frame(This=c("120", "60", "90", "OG"), That=c(453, 679,12,252))
DATA
This That
1 120 453
2 60 679
3 90 12
4 OG 252
I want to sort it in the order 60 - 90 - 120 - OG, i.e.
This That
1 60 679
2 90 12
3 120 453
4 OG 252
Edit: This is not a duplicate question. As explained above, and in the comment below, the sorting is arbitrary. Lexicographical sorting assumes the row names are inter-related, that isn't the case here. I could have labelled the rows ("unicorn", "18.1", "TREES", "234234235")
and wanted them in the order ("234234235", "unicorn", "TREES", "18.1")