Replace all occurrences of given values in all columns of a data frame. Factor levels are preserved (and extended by the replacement values), and numeric/logical columns are only touched where a value actually matches, so unrelated entries keep their exact binary representation.
Examples
# \donttest{
data <- data.frame(
q1 = c("neg2", "neg1", "0"),
q2 = c("1", "neg2", "neg1")
)
replace_values(
data,
to_replace = c("neg2", "neg1"),
replace_with = c("-2", "-1")
)
#> q1 q2
#> 1 -2 1
#> 2 -1 -2
#> 3 0 -1
# }