Crunch categorical variables have slightly richer metadata than R's factor variables. This function generates a list of category data from a factor's levels which can then be further manipulated in R before being imported into Crunch.
categoriesFromLevels(level_vect)
A character vector containing the levels of a factor. Usually
obtained by running base::levels()
A list with each category levels id, name, numeric_value, and missingness.
categoriesFromLevels(levels(iris$Species))
#> [[1]]
#> [[1]]$id
#> [1] 1
#>
#> [[1]]$name
#> [1] "setosa"
#>
#> [[1]]$numeric_value
#> [1] 1
#>
#> [[1]]$missing
#> [1] FALSE
#>
#>
#> [[2]]
#> [[2]]$id
#> [1] 2
#>
#> [[2]]$name
#> [1] "versicolor"
#>
#> [[2]]$numeric_value
#> [1] 2
#>
#> [[2]]$missing
#> [1] FALSE
#>
#>
#> [[3]]
#> [[3]]$id
#> [1] 3
#>
#> [[3]]$name
#> [1] "virginica"
#>
#> [[3]]$numeric_value
#> [1] 3
#>
#> [[3]]$missing
#> [1] FALSE
#>
#>
#> [[4]]
#> [[4]]$id
#> [1] -1
#>
#> [[4]]$name
#> [1] "No Data"
#>
#> [[4]]$numeric_value
#> NULL
#>
#> [[4]]$missing
#> [1] TRUE
#>
#>