Saturday, 15 September 2012

r - Ordering the data based on 2 columns in a data frame -



r - Ordering the data based on 2 columns in a data frame -

i have info frame x columns a,b,c.

i trying order info based on columns , c , ordering criteria ascending on , descending on c. below code wrote.

z <- x[order(x$a,-x$c),]

this code gives me warning below.

warning message: in ops.factor(x$c) : - not meaningful factors

also, when check info frame z using head(z), gives me wrong info below:

30708908 0.3918980 na 22061768 0.4022183 na 21430343 0.4118651 na 21429828 0.4134888 na 21425966 0.4159323 na 22057521 0.4173094 na

and there wasnt na values of column c in info frame x. have gone through lot of threads couldn't find solution. can please suggest.

try this

install.packages('plyr'); library('plyr'); z<-arrange(x,a,desc(c));

in addition, can utilize

options(stringsasfactors = false)

before create frame, or while creating 'x' info frame, specify

stringsasfactors = false

r

No comments:

Post a Comment