Build a codelist data.frame from observed data values
Source:R/metacore_lite.R
codelist_from_data.RdBuilds a minimal `code`/`decode` codelist data.frame from the unique values of `data[[var]]`: `decode` is `sort(unique(...))` of the non-missing values and `code` is `seq_along(decode)`. The result is suitable as an entry of the `codelists` argument of [mock_metacore()], e.g. `codelists = list(RACE = codelist_from_data("RACE", dm))`.
Value
A data.frame with columns `code` (integer) and `decode` (character), one row per unique non-missing value, sorted by decode.
Examples
dm <- data.frame(RACE = c("WHITE", "ASIAN", "BLACK", "ASIAN"))
codelist_from_data("RACE", dm)
#> code decode
#> 1 1 ASIAN
#> 2 2 BLACK
#> 3 3 WHITE