The R Project SVN R

Rev

Rev 24604 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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