Replaces factor levels with arbitary 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 × 2 #> f n #> <fctr> <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 × 2 #> f n #> <fctr> <int> #> 1 01 689 #> 2 02 93 #> 3 03 23 #> 4 04 5124 #> 5 05 104 #> 6 06 95 #> 7 07 224 #> 8 08 147 #> 9 09 109 #> 10 10 388 #> 11 11 71 #> 12 12 3523 #> 13 13 15 #> 14 14 10846 #> 15 15 32 #> 16 16 0
gss_cat$relig %>% fct_anon() %>% fct_count()
#> # A tibble: 16 × 2 #> f n #> <fctr> <int> #> 1 01 15 #> 2 02 32 #> 3 03 3523 #> 4 04 689 #> 5 05 388 #> 6 06 109 #> 7 07 93 #> 8 08 95 #> 9 09 0 #> 10 10 71 #> 11 11 104 #> 12 12 5124 #> 13 13 23 #> 14 14 147 #> 15 15 224 #> 16 16 10846
gss_cat$relig %>% fct_anon("X") %>% fct_count()
#> # A tibble: 16 × 2 #> f n #> <fctr> <int> #> 1 X01 388 #> 2 X02 104 #> 3 X03 5124 #> 4 X04 147 #> 5 X05 93 #> 6 X06 23 #> 7 X07 109 #> 8 X08 3523 #> 9 X09 689 #> 10 X10 15 #> 11 X11 95 #> 12 X12 10846 #> 13 X13 71 #> 14 X14 224 #> 15 X15 32 #> 16 X16 0