code | R Documentation |
A code vector is a vector with an associated code list. The values in the
vector should come from this code list. The values also have an associated
label and optionally additional properties such as a description. See
codelist
for more information on what should and could be in a
code list.
code(x, codelist, ...)
x |
vector to convert to code vector |
codelist |
code list to associate with the values in |
... |
Ignored; used to pass extra arguments to other methods |
When codelist
is omitted when case x
is a factor, a code list is
generated from the factor values.
Returns an object of type 'code'. Except when x
is a factor, x
keeps classes and attributes assiated with x
. This object is a copy of
x
with a codelist
attribute added.
When x
is a factor x
it converted to an integer vector. The
labels are the levels of the factor.
x <- code(c(1,4,2), codelist(codes = 1:4, labels = letters[1:4]))
print(x)
labels(x)
x <- code(factor(letters[1:3]))
print(x)
attr(x, "codelist")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.