Skip to contents

Turns a dic variable into a factor based on the value labels

Usage

factor_by_label(x)

Arguments

x

A vector with dic information.

Value

A factor

Examples

dat_dic <- apply_dic(ex_scaledic_data, ex_scaledic_dic)
#> 
#> 1: Missing values replaced with NA
# Proportions of responses
dat_dic$rel_2 |> factor_by_label() |> table() |> prop.table()
#> Error in factor(x, labels = labels): invalid 'labels'; length 6 should be 1 or 7
# A cross table
table(factor_by_label(dat_dic$rel_1), dat_dic$gender)
#>                      
#>                       m f d
#>   Never               0 1 1
#>   Once a year or less 1 2 1
#>   A few times a year  1 1 3
#>   A few times a month 0 1 0
#>   Once a week         1 1 0
#>   More than once/week 4 1 0