Jonathan Greenberg
2004-Feb-14 23:10 UTC
[R] Converting a number column to a factor in a data frame?
Is there an easy way of taking a dataframe which is comprised of only numbers, and converting one of the integer columns to a factor column? How do I go about this? --j -- Jonathan Greenberg Graduate Group in Ecology, U.C. Davis http://www.cstars.ucdavis.edu/~jongreen http://www.cstars.ucdavis.edu AIM: jgrn307 or jgrn3007 MSN: jgrn307 at msn.com or jgrn3007 at msn.com
Andy Bunn
2004-Feb-14 23:19 UTC
[R] Converting a number column to a factor in a data frame?
Look at ?as.factor HTH, Andy ## Example # Make some data foo.df <- data.frame(X1 = rnorm(10), X2 = runif(10), Y = round(runif(10) + 1)) # Summarize it summary(foo.df) # Tak an extra close look at column Y class(foo.df$Y) # Change Y to a factor foo.df$Y <- as.factor(foo.df$Y) # Look at it again summary(foo.df) class(foo.df$Y) levels(foo.df$Y)