r - as.data.frame and cbind results in factor columns -
i have big data.frame mix of integer, character , strings columns. i'll need order data.frame numeric column.
when combine original columns data.frame columns change factor, including column need sort. sort gives 1, 10, 100...
instead of 1, 2, 3...
here example of problem.
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)) # using construction e <- d[with(d, order(b)), ]
how can fix this?
actually need do:
d <- data.frame(a, b, c, stringsasfactors=false)
the last part stringsasfactors=false
prevents column d$c
being converted factors. include it, , strings stay strings.
don't forget stringsasfactors=false
- save untold misery, trust me!
Comments
Post a Comment