relevel_columns: Relevel many factor columns in a data frame at once

View source: R/data_manip_utils.R

relevel_columnsR Documentation

Relevel many factor columns in a data frame at once

Description

This is a shortcut for calling forcats::fct_relevel() on multiple columns of a data frame.

Usage

relevel_columns(df, ...)

Arguments

df

The data frame in which to re-level some factor columns.

...

Additional arguments control the re-leveling of factors. The name of each argument indicates the column of df to re-level (this column should be a factor). The value should be the new levels in the order that they should appear (or any valid list of arguments to forcats::fct_relevel()).

Value

df, with the specified factor columns re-leveled according to the provided specifications.

Examples


x <- data.frame(a = letters[1:2], b = LETTERS[1:6])
sapply(x, levels)
x2 <- relevel_columns(x, a = c("b", "a"), b = list("B", "A", after = 2))
sapply(x2, levels)


DarwinAwardWinner/rctutils documentation built on July 22, 2022, 5:19 a.m.