.BG
.VE $Header: /usr/s/current/s/.help/RCS/code,v 1.4 86/06/02 09:34:59 rab Exp $
.FN code
.TL
code: Create Category from Discrete Data
.CS
code(x, levels, labels)
.PP
.AG x
data vector.  Missing values (NAs) are allowed.
.AG levels
optional vector of levels that the category should have.
Any data value that does not match a value in `levels' is
coded in the output `Data' vector as NA. 
Missing values (NAs) are allowed.  Default is
the set of unique values in `x', sorted in ascending order,
with NAs omitted.
.AG labels
optional vector of values to use as labels for the levels of
the category.  By default, the vector of levels is used.
.RT
category structure with components `Data' and `Label'.
.RC Data
integer vector indicating which level the category took on
for each data value.  NAs are returned where a data value in
`x' did not match any value in `levels'.
.RC Label
character names for the levels of the category.  If the
argument `labels' (either given or default) was not of mode
CHAR, it will have been encoded.
.EX
code(occupation)  # "doctor", "lawyer", etc.

# make readable labels
occ <- code(occupation,levels=c("d","l"),labels=c("Doctor","Lawyer"))

# turn category into character vector
occ$Label [ occ ]

colors <- code(color,c("red","blue","green"))
tprint(table(colors))   #print table counting occurrences of colors
.KW basic*
.KW category
.WR
