[R] converting column to factor *within* a data frame

Pascal A. Niklaus Pascal.Niklaus at unibas.ch
Wed Nov 5 09:50:01 CET 2003


Hi all,

I repeatedly encounter the following problem: After importing a data set 
into a data frame, I wish to set a column with numeric values to be a 
factor, but can't figure out how to do this. Also, I do not wish to 
write as.factor(x) all the time. I can create a new vector with x <- 
factor(x), but the new vector resides outside the attached data frame.

Pascal

 > attach(ngrad)
 > is.factor(STNW)
[1] FALSE

 > ngrad$STNW<-factor(STNW)  ## doesn't work
 > is.factor(STNW)
[1] FALSE

 > is.factor(STNW) <- T    ## doesn't work either
Error: couldn't find function "is.factor<-"




More information about the R-help mailing list