Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

mapValues

Replace values in atomic vectors


Description

Replace values in atomic vectors

Usage

mapValues(x, from, to, regex = FALSE, ignore.case = FALSE, perl = FALSE,
  fixed = FALSE)

Arguments

x

[atomic]
Atomic vector. If x is a factor, all replacements work on the levels.

from

[atomic]
Atomic vector with values to replace, same length as to.

to

[atomic]
Atomic vector with replacements, same length as from.

regex

[logical]
Use regular expression matching? Default is FALSE.

ignore.case

[logical]
Argument passed to gsub.

perl

[logical]
Argument passed to gsub.

fixed

[logical]
Argument passed to gsub.

Details

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.

Value

[atomic].

Examples

# 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)

BBmisc

Miscellaneous Helper Functions for B. Bischl

v1.11
BSD_2_clause + file LICENSE
Authors
Bernd Bischl [aut, cre], Michel Lang [aut], Jakob Bossek [aut], Daniel Horn [aut], Jakob Richter [aut], Dirk Surmann [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.