Replaces factor levels with arbitrary numeric identifiers. Neither the values nor the order of the levels are preserved.

fct_anon(f, prefix = "")

Arguments

f

A factor.

prefix

A character prefix to insert in front of the random labels.

Examples

gss_cat$relig %>% fct_count()
#> # A tibble: 16 x 2 #> f n #> <fct> <int> #> 1 No answer 93 #> 2 Don't know 15 #> 3 Inter-nondenominational 109 #> 4 Native american 23 #> 5 Christian 689 #> 6 Orthodox-christian 95 #> 7 Moslem/islam 104 #> 8 Other eastern 32 #> 9 Hinduism 71 #> 10 Buddhism 147 #> 11 Other 224 #> 12 None 3523 #> 13 Jewish 388 #> 14 Catholic 5124 #> 15 Protestant 10846 #> 16 Not applicable 0
gss_cat$relig %>% fct_anon() %>% fct_count()
#> # A tibble: 16 x 2 #> f n #> <fct> <int> #> 1 01 10846 #> 2 02 3523 #> 3 03 5124 #> 4 04 95 #> 5 05 23 #> 6 06 689 #> 7 07 15 #> 8 08 147 #> 9 09 32 #> 10 10 388 #> 11 11 0 #> 12 12 109 #> 13 13 93 #> 14 14 104 #> 15 15 224 #> 16 16 71
gss_cat$relig %>% fct_anon("X") %>% fct_count()
#> # A tibble: 16 x 2 #> f n #> <fct> <int> #> 1 X01 147 #> 2 X02 689 #> 3 X03 71 #> 4 X04 104 #> 5 X05 15 #> 6 X06 95 #> 7 X07 5124 #> 8 X08 3523 #> 9 X09 10846 #> 10 X10 0 #> 11 X11 93 #> 12 X12 23 #> 13 X13 32 #> 14 X14 388 #> 15 X15 109 #> 16 X16 224