Rev 6098 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{codes}\title{Factor Codes}\usage{codes(x)codes(x) <- value}\alias{codes}\alias{codes.factor}\alias{codes.ordered}\alias{codes<-}\description{This (generic) function returns a numeric coding of afactor. It can also be used to assign to a factor using the codedform.}\value{For an ordered factor, it returns the internal coding (1 forthe lowest group, 2 for the second lowest, etc.).For an unorderedfactor, an alphabetical ordering of the levels is assumed, i.e thelevel that is coded 1 is the one whose name is sorted first accordingto the prevailing collating sequence. \bold{Warning:} the sort ordermay well depend on the locale, and should not be assumed to be ASCII.}\note{Normally \code{codes} is not the appropriate function to use with anunordered factor. Use \code{\link{unclass}} or\code{\link{as.numeric}} to extract the codes used in the internalrepresentation of the factor, as these do not assume that the codesare sorted.}\seealso{\code{\link{factor}}, \code{\link{levels}}, \code{\link{nlevels}}.}\examples{codes(rep(factor(c(20,10)),3))x <- gl(3,5)codes(x)[3] <- 2xdata(esoph)( ag <- esoph$alcgp[12:1] )codes(ag)codes(factor(1:10)) # BEWARE!}\note{The behaviour for unordered factors is dubious, but compatiblewith S version 3. To get the internal coding of a factor, use\code{\link{as.integer}}. Note in particular that the codes may not bethe same in different language locales because of collatingdifferences.}\keyword{category}\keyword{classes}