Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

refactor

Remove/reorder levels


Description

Remove/reorder levels

Usage

refactor(x, levs = levels(x), repl = NA)

Arguments

x

Character or Factor

levs

Set of levels to use

repl

String (or NA) used to replace missing levels

Details

Keep only a specific set of levels in a factor. By removing levels the base for comparison in, e.g., regression analysis, becomes the first level. To relabel the base use, for example, repl = 'other'

Examples

refactor(diamonds$cut, c("Premium","Ideal")) %>% head()
refactor(diamonds$cut, c("Premium","Ideal"), "Other") %>% head()

radiant.data

Data Menu for Radiant: Business Analytics using R and Shiny

v1.3.12
AGPL-3 | file LICENSE
Authors
Vincent Nijs [aut, cre]
Initial release
2020-11-25

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.