Description Usage Arguments Details Examples
Item in x that match items from will be replaced by items in to, matched by position. For example, items in x that match the first element in from will be replaced by the first element of to.
1 | map_values(x, from, to, warn_missing = TRUE)
|
x |
the factor or vector to modify |
from |
a vector of the items to replace |
to |
a vector of replacement values |
warn_missing |
print a message if any of the old values are not actually present in x |
If x is a factor, the matching levels of the factor will be replaced with the new values. The related revalue function works only on character vectors and factors, but this function works on vectors of any type and factors.
1 2 3 4 5 6 7 8 9 10 | x <- c("a", "b", "c")
map_values(x, c("a", "c"), c("A", "C"))
# Works on factors
y <- factor(c("a", "b", "c", "a"))
map_values(y, c("a", "c"), c("A", "C"))
# Works on numeric vectors
z <- c(1, 4, 5, 9)
map_values(z, from = c(1, 5, 9), to = c(10, 50, 90))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.