Description Usage Arguments See Also Examples

Lump together least/most common factor levels into "other"

1 2 |

`f` |
A factor. |

`n, prop` |
If both Positive Positive |

`other_level` |
Value of level used for "other" values. Always placed at end of levels. |

`ties.method` |
A character string specifying how ties are
treated. See |

`fct_other()`

to convert specified levels to other.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ```
x <- factor(rep(LETTERS[1:9], times = c(40, 10, 5, 27, 1, 1, 1, 1, 1)))
x %>% table()
x %>% fct_lump() %>% table()
x %>% fct_lump() %>% fct_inorder() %>% table()
x <- factor(letters[rpois(100, 5)])
x
table(x)
table(fct_lump(x))
# Use positive values to collapse the rarest
fct_lump(x, n = 3)
fct_lump(x, prop = 0.1)
# Use negative values to collapse the most common
fct_lump(x, n = -3)
fct_lump(x, prop = -0.1)
# Use ties.method to control how tied factors are collapsed
fct_lump(x, n = 6)
fct_lump(x, n = 6, ties.method = "max")
``` |

forcats documentation built on May 30, 2017, 6:35 a.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.