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

revalue

Replace specified values with new values, in a factor or character vector.


Description

If x is a factor, the named levels of the factor will be replaced with the new values.

Usage

revalue(x, replace = NULL, warn_missing = TRUE)

Arguments

x

factor or character vector to modify

replace

named character vector, with new values as values, and old values as names.

warn_missing

print a message if any of the old values are not actually present in x

Details

This function works only on character vectors and factors, but the related mapvalues function works on vectors of any type and factors, and instead of a named vector specifying the original and replacement values, it takes two separate vectors

See Also

mapvalues to replace values with vectors of any type

Examples

x <- c("a", "b", "c")
revalue(x, c(a = "A", c = "C"))
revalue(x, c("a" = "A", "c" = "C"))

y <- factor(c("a", "b", "c", "a"))
revalue(y, c(a = "A", c = "C"))

plyr

Tools for Splitting, Applying and Combining Data

v1.8.6
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre]
Initial release

We don't support your browser anymore

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