levelcast | R Documentation |
Recode codes to a higher level in a hierarchy
levelcast(
x,
level,
codelist = attr(x, "codelist"),
over_level = c("error", "missing", "ignore"),
filter_codelist = TRUE
)
x |
vector of codes to record. This can be an object of type
|
level |
level to which to cast the codes. |
codelist |
the |
over_level |
how to handle codes that are in a higher level than the level that is cast to. The default 'error' will generate an error; 'missing' will result in missing values for those codes; 'ignore' will keep these codes. |
filter_codelist |
if |
When handling codes that are in a higher level than the level that is cast to, codes that are missing values are ignored as these are often in the highest level.
A vector with the same length as x
.
cl <- codelist(
codes = c("A", "B", "A1", "A2", "B1", "B2", "A1.1", "B2.2", "X"),
parent = c(NA, NA, "A", "A", "B", "B", "A1", "B2", NA),
missing = c(0, 0, 0, 0, 0, 0, 0, 0, 1)
)
x <- code(c("A1.1", "A1", "A2", "B2.2", "B2.2", NA, "B2", "X"), cl)
levelcast(x, 1)
levelcast(x, 2, over_level = "ignore")
levelcast(x, 0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.