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