[R] Non-standard sorts on vectors
chipmaney
chipmaney at hotmail.com
Thu Aug 26 23:59:56 CEST 2010
I have a dataset I need to sort:
test.df<-data.frame(Zone=c("Floodplain", "Lake",
"Shoreline"),Cover=c(50,60,70))
However, I don't want it sorted ascending/descending but in an order that I
define via a vector:
sort.v<-data.frame(c("Lake","Shoreline","Floodplain"))
I realize I could probably just create the vector of [factors] in the order
I want, then assign the value:
sort.v$Cover<-test.df$Cover
However, this is inefficient. Is there source code or a syntactical trick
that will do the same more efficiently? Note: I have investigated order()
and sort(), but neither seems to have an argument for defining the sorting
order.
Thanks in advance, Chipper
--
View this message in context: http://r.789695.n4.nabble.com/Non-standard-sorts-on-vectors-tp2340431p2340431.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list