fct_clean: A function to applied some forcats functions

View source: R/forcats.R

fct_cleanR Documentation

A function to applied some forcats functions

Description

A function to applied some forcats functions

Usage

fct_clean(
  x,
  na_level = "(Missing)",
  n = NULL,
  other_level = "Other",
  infreq = TRUE
)

Arguments

x

A vector

na_level

If this argument is not null, then 'fct_explicit_na' is applied with this argument.

n

If this argument is not null, then 'fct_lump_n' is applied with 'n' and 'other_level'.

other_level

this argument is used if 'n' is not null.

infreq

Logical value to apply or not 'fct_infreq'.

Examples


x1 <- c(rep(LETTERS[1:9], times = c(10, 40, 5, 27, 1, 1, 1, 1, 1)), rep(NA, 10))
x2 <- factor(x1)

table(x1, useNA = "always")
table(x2, useNA = "always")

identical(fct_clean(x1), fct_clean(x2))

xf <- fct_clean(x1, n = 4)
xf

table(xf, useNA = "always")


jbkunst/kunstomverse documentation built on May 30, 2022, 12:15 a.m.