replacefactor: Replace Factor Values

replacefactorR Documentation

Replace Factor Values

Description

This function lets the user replace levels on a factor vector.

Usage

replacefactor(x, original, change)

Arguments

x

Factor (or Character) Vector

original

String or Vector. Original text you wish to replace

change

String or Vector. Values you wish to replace the originals with

Value

Factor vector with transformed levels.

See Also

Other Data Wrangling: balance_data(), categ_reducer(), cleanText(), date_cuts(), date_feats(), file_name(), formatHTML(), holidays(), impute(), left(), normalize(), num_abbr(), ohe_commas(), ohse(), quants(), removenacols(), replaceall(), textFeats(), textTokenizer(), vector2text(), year_month(), zerovar()

Examples

library(dplyr)
data(dft)
# Replace a single value
dft <- mutate(dft, Pclass = replacefactor(Pclass, original = "1", change = "First"))
levels(dft$Pclass)
# Replace multiple values
dft <- mutate(dft, Pclass = replacefactor(Pclass, c("2", "3"), c("Second", "Third")))
levels(dft$Pclass)

laresbernardo/lares documentation built on Oct. 23, 2024, 12:05 p.m.