replacefactor | R Documentation |
This function lets the user replace levels on a factor vector.
replacefactor(x, original, change)
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 |
Factor vector with transformed levels.
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()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.