Rev 24300 | Rev 36992 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{levels}\alias{levels}\alias{levels<-}\alias{levels<-.default}\alias{levels<-.factor}\title{Levels Attributes}\usage{levels(x)levels(x) <- value}\description{\code{levels} provides access to the levels attribute of a variable.The first form returns the value of the levels of its argumentand the second sets the attribute.The assignment form (\code{"levels<-"}) of \code{levels} is a genericfunction and new methods can be written for it.The most important method is that for \code{\link{factor}}s:}\arguments{\item{x}{an object, for example a factor.}\item{value}{A valid value for \code{levels(x)}.For the default method, \code{NULL} or a character vector. For the\code{factor} method, a vector of character strings with length atleast the number of levels of \code{x}, or a named list specifying how torename the levels.}}\references{Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)\emph{The New S Language}.Wadsworth \& Brooks/Cole.}\seealso{\code{\link{nlevels}}.}\examples{## assign individual levelsx <- gl(2, 4, 8)levels(x)[1] <- "low"levels(x)[2] <- "high"x## or as a groupy <- gl(2, 4, 8)levels(y) <- c("low", "high")y## combine some levelsz <- gl(3, 2, 12)levels(z) <- c("A", "B", "A")z## same, using a named listz <- gl(3, 2, 12)levels(z) <- list(A=c(1,3), B=2)z## we can add levels this way:f <- factor(c("a","b"))levels(f) <- c("c", "a", "b")ff <- factor(c("a","b"))levels(f) <- list(C="C", A="a", B="b")f}\keyword{category}