Description Usage Arguments Value See Also Examples
Polychoric correlation routines often limit the number of levels an
ordinal (ordered categorical) factor can have.
This function is like forcats::fct_collapse()
but preserves the ordering of levels.
Modified factors are releveled to 1:n.
1 | ord_collapse(.data, maxlev = 10, newlev = maxlev)
|
.data |
data frame with ordinal factors coded as integers |
maxlev |
apply level collapsing only if |
newlev |
if collapsing levels, how many levels should the factor have.
Default is |
data frame with same columns
Other data munging:
drop_nzv()
,
dummy_code()
1 2 3 4 5 | library(dplyr)
mtcars %>%
mutate(across(c("cyl", "vs", "am", "gear", "carb", "disp"), as.ordered)) %>%
ord_collapse() %>%
summarise_all(nlevels)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.