BoutrosLab.plotting.general (version 5.9.2)

recode.vector: Recode Vector

Description

Recode a vector based on a set of lookup values

Usage

recode.vector(x, lookup, drop = FALSE);

Arguments

x

vector to recode

lookup

list with mappings of x to new values

drop

should values in x not found in lookup be dropped i.e. set to NA, defaults to FALSE

Value

recoded vector

Details

When using factors to recode data there tends to be issues with values being dropped if not specified in levels. Recode.vector gets around that.

Examples

Run this code
# NOT RUN {
a <- c(letters, NA);
b <- list(abc = c("a","b","c"), missing = NA);
d <- recode.vector(x = a, lookup = b)

# }

Run the code above in your browser using DataLab