I have a big data.frame with a mix of integer, character and strings columns. I'll need to order the data.frame by a numeric column.
When I combine the original columns into a data.frame all the columns change to factor, including the column I need for the sort. So the sort gives something like
1, 10, 100...
1, 2, 3...
a <- 1:10
b <- c(1,3,5,6,2,10,100,110,7,4)
c <- LETTERS[1:10]
d <- as.data.frame(cbind(a, b, c)) # I am using this construction
e <- d[with(d, order(b)), ]
Actually you need to do:
d <- data.frame(a, b, c, stringsAsFactors=FALSE)
The last part
stringsAsFactors=FALSE prevents column
d$c from being converted to factors. Include it, and your strings will stay as strings.
stringsAsFactors=FALSE - it will save you untold misery, trust me!