replaceall: Replace Values With

replaceallR Documentation

Replace Values With

Description

This function lets the user replace all specific values in a vector or data.frame into another value. If replacing more than one value, order matters so they will be replaced in the same order that you pass them to the function. Factors will be refactored.

Usage

replaceall(df, original, change, which = "all", fixclass = TRUE, quiet = TRUE)

Arguments

df

Data.frame or Vector

original

String or Vector. Original text you wish to replace

change

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

which

Character vector. Name of columns to use. Leave "all" for everything

fixclass

Boolean. Try to detect logical classes after transformations (or leave as default classes as character)?

quiet

Boolean. Keep quiet? (or print replacements)

Value

data.frame with replaced values based on inputs.

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(), replacefactor(), textFeats(), textTokenizer(), vector2text(), year_month(), zerovar()

Other Text Mining: cleanText(), ngrams(), remove_stopwords(), sentimentBreakdown(), textCloud(), textFeats(), textTokenizer(), topics_rake()

Examples

df <- data.frame(
  one = c(1:4, NA),
  two = LETTERS[1:5],
  three = rep("A", 5),
  four = c(NA, "Aaa", 123, "B", "C")
)
print(df)

replaceall(df, "A", NA)

replaceall(df, "A", "a")

replaceall(df, 1, "*")

replaceall(df, NA, "NotNA")

replaceall(df, NA, 0)

replaceall(df, c("A", "B"), c("'A'", "'B'"))

replaceall(df, "a", "*", which = "four")

lares documentation built on Sept. 13, 2024, 1:08 a.m.