| 25384 |
ripley |
1 |
\name{codes-deprecated}
|
| 24604 |
ripley |
2 |
\alias{codes-deprecated}
|
| 15168 |
pd |
3 |
\title{Factor Codes}
|
| 6098 |
pd |
4 |
\description{
|
| 15168 |
pd |
5 |
This (generic) function returns a numeric coding of a factor. It can
|
|
|
6 |
also be used to assign to a factor using the coded form.
|
| 24604 |
ripley |
7 |
|
|
|
8 |
It is now \code{\link{Deprecated}}.
|
| 6098 |
pd |
9 |
}
|
| 15168 |
pd |
10 |
\usage{
|
|
|
11 |
codes(x, \dots)
|
| 24158 |
hornik |
12 |
codes(x, \dots) <- value
|
| 15168 |
pd |
13 |
}
|
| 15518 |
ripley |
14 |
\arguments{
|
|
|
15 |
\item{x}{an object from which to extract or set the codes.}
|
|
|
16 |
\item{\dots}{further arguments passed to or from other methods.}
|
| 24604 |
ripley |
17 |
\item{value}{replacement value.}
|
| 15518 |
ripley |
18 |
}
|
| 6098 |
pd |
19 |
\value{
|
| 15168 |
pd |
20 |
For an ordered factor, it returns the internal coding (1 for the
|
|
|
21 |
lowest group, 2 for the second lowest, etc.).
|
| 2016 |
pd |
22 |
|
| 15168 |
pd |
23 |
For an unordered factor, an alphabetical ordering of the levels is
|
|
|
24 |
assumed, i.e., the level that is coded 1 is the one whose name is
|
|
|
25 |
sorted first according to the prevailing collating sequence.
|
|
|
26 |
\bold{Warning:} the sort order may well depend on the locale, and
|
|
|
27 |
should not be assumed to be ASCII.
|
| 6098 |
pd |
28 |
}
|
|
|
29 |
\note{
|
| 15168 |
pd |
30 |
Normally \code{codes} is not the appropriate function to use with an
|
|
|
31 |
unordered factor. Use \code{\link{unclass}} or
|
|
|
32 |
\code{\link{as.numeric}} to extract the codes used in the internal
|
|
|
33 |
representation of the factor, as these do not assume that the codes
|
|
|
34 |
are sorted.
|
|
|
35 |
|
|
|
36 |
The behaviour for unordered factors is dubious, but compatible with S
|
|
|
37 |
version 3. To get the internal coding of a factor, use
|
|
|
38 |
\code{\link{as.integer}}. Note in particular that the codes may not
|
|
|
39 |
be the same in different language locales because of collating
|
|
|
40 |
differences.
|
| 6098 |
pd |
41 |
}
|
| 2 |
r |
42 |
\seealso{
|
| 2016 |
pd |
43 |
\code{\link{factor}}, \code{\link{levels}}, \code{\link{nlevels}}.
|
| 2 |
r |
44 |
}
|
| 24604 |
ripley |
45 |
\examples{\dontrun{
|
| 2016 |
pd |
46 |
codes(rep(factor(c(20,10)),3))
|
|
|
47 |
|
| 1055 |
maechler |
48 |
x <- gl(3,5)
|
| 2 |
r |
49 |
codes(x)[3] <- 2
|
| 2016 |
pd |
50 |
x
|
|
|
51 |
|
|
|
52 |
data(esoph)
|
|
|
53 |
( ag <- esoph$alcgp[12:1] )
|
|
|
54 |
codes(ag)
|
|
|
55 |
|
|
|
56 |
codes(factor(1:10)) # BEWARE!
|
| 24604 |
ripley |
57 |
}}
|
| 286 |
maechler |
58 |
\keyword{category}
|
|
|
59 |
\keyword{classes}
|
| 2016 |
pd |
60 |
|
|
|
61 |
|