[R] Converting a number column to a factor in a data frame?
Andy Bunn
abunn at montana.edu
Sun Feb 15 00:19:36 CET 2004
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)
More information about the R-help
mailing list