dp_to_factor | R Documentation |
Recode a variable to factor using the associated categories
dp_to_factor(x, categorieslist = dp_categorieslist(x), warn = TRUE)
x |
the variable to recode |
categorieslist |
a |
warn |
give a warning when there is no code list. |
By setting the option 'DP_TRIM_CODE' to TRUE
white space at the
beginning and end of character values will be ignored when comparing x
and the category values. Also multiple hyphens at the beginning character
values will be ignored. This can be disabled by setting the option
'DP_TRIM_HYPHEN' to FALSE
.
Returns a factor vector or x
when no categories could be found
(categorieslist = NULL
).
An alternative is the dp_to_code
function to convert to
'code' object from the 'codelist' package.
fn <- system.file("examples/iris", package = "datapackage")
dp <- open_datapackage(fn)
dta <- dp |> dp_get_data("complex", convert_categories = "no")
dp_to_factor(dta$factor1)
dp |> dp_get_data("complex", convert_categories = "to_factor")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.