Recode a vector based on a set of lookup values
recode.vector(x, lookup, drop = FALSE);
vector to recode
list with mappings of x to new values
should values in x not found in lookup be dropped i.e. set to NA, defaults to FALSE
recoded vector
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.
# 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