Learn R Programming

iNZightTools (version 1.13.0)

renameLevels: Rename the levels of a categorical variable

Description

Rename the levels of a categorical variables, and returns the result along with tidyverse code used to generate it.

Usage

renameLevels(.data, var, to_be_renamed, name = sprintf("%s.rename", var))

Value

original dataframe containing a new column of the renamed categorical variable with tidyverse code attached

Arguments

.data

a dataframe with the column to be renamed

var

a character of the categorical variable to rename

to_be_renamed

a list of the old level name assigned to the new level name; i.e., `list('new level name' = 'old level name')`

name

a name for the new variable

Author

Owen Jin

See Also

code

Examples

Run this code
renamed <- renameLevels(iris, var = "Species",
    to_be_renamed = list(set = "setosa", ver = "versicolor"))
cat(code(renamed))
head(renamed)

Run the code above in your browser using DataLab