data vector.
Missing values (
NAs) and
Infs are allowed.
OPTIONAL ARGUMENTS:
levels
vector of levels for the category;
by default, the sorted unique values in
x (that are not in
exclude if
exclude is not
NULL).
If
levels is supplied an value in
x but not in
levels will be
NA
in the result.
The argument
exclude is ignored when
levels is supplied.
Missing values (
NAs) and special values (
NaNs and
Infs) are allowed.
labels
vector of character strings to use as labels for the levels of the category.
The lengths of
labels and
levels must match.
ordered
if
TRUE, the attribute
ordered is added to the return vector with
value
TRUE.
exclude
a vector of values to be excluded from forming levels.
Any value that appears in both
x and
exclude will be
NA in the
result and it will not appear in the default
levels attribute.
VALUE:
vector of integers with
levels attribute, indicating which level the
category takes on for each data value.
Any data value that does not match a value in
levels is
coded in the output vector as
NA.
Think of the return value as a subscript into the
levels attribute.
is.category returns
TRUE if
x is a category object (has "levels"), and
returns
FALSE otherwise.
as.category returns
x, if
x is a category,
category(x) otherwise.
SEE ALSO:
,
,
,
,
,
,
.
EXAMPLES:
category(occupation) # "doctor", "lawyer", etc.
category(occupation, exclude=NA)
# NAs in the vector rather than a level for NAs
# make readable labels
occ <- category(occupation,level=c("d","l"),
label=c("Doctor","Lawyer"))
# turn category into character vector
occ.char <- levels(occ)[occ]
colors <- category(color,c("red","green","blue"))
table(colors) #table counting occurrences of colors