powered by
Replace values in atomic vectors
mapValues( x, from, to, regex = FALSE, ignore.case = FALSE, perl = FALSE, fixed = FALSE )
[atomic].
atomic
[atomic] Atomic vector. If x is a factor, all replacements work on the levels.
x
[atomic] Atomic vector with values to replace, same length as to.
to
[atomic] Atomic vector with replacements, same length as from.
from
[logical] Use regular expression matching? Default is FALSE.
logical
FALSE
[logical] Argument passed to gsub.
gsub
Replaces values specified in from with values in to. Regular expression matching can be enabled which calls gsub iteratively on x to replace all patterns in from with replacements in to.
# replace integers x = 1:5 mapValues(x, c(2, 3), c(99, 100)) # replace factor levels using regex matching x = factor(c("aab", "aba", "baa")) mapValues(x, "a.a", "zzz", regex = TRUE)
Run the code above in your browser using DataLab