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