[R] Reordering levels of a factor when the factor is part of a data frame

Ernest Adrogué nfdisco at gmail.com
Mon Feb 6 21:29:22 CET 2012


 6-02-2012, 11:03 (-0800); Judith Flores escriu:
> The name of the column will be saved in an object called:
> 
> variab
> 
> the data frame is called df.
> 
> 
> If I try to the do following:
> 
> df[variab]<-factor(df[variab], levels=c("A2B","B31","C33"))
> 
> it won't work because df[variab] is a data frame. 

I think you need to use df[[variab]] instead.

Cheers,
Ernest



More information about the R-help mailing list