recodeLookup: Recode a variable according to a lookup table

Description Usage Arguments Value Examples

Description

Recodes the values of a variable. Function resembles the recode function from the car package, but uses a lookup table to specify old and new values.

Usage

1
recodeLookup(var, lookup)

Arguments

var

a vector (e.g. numeric, character, or factor)

lookup

a data.frame with exact two columns. First column contains old values, second column new values. Values which do not occur in the old column remain unchanged.

Value

a vector of the same length as var with recoded values

Examples

1
2
3
num_var <- sample(1:10, size = 10, replace = TRUE)
lookup  <- data.frame(old = c(2, 4, 6), new = c(200,400,600))
num_var2<- recodeLookup(num_var, lookup)

eatTools documentation built on Nov. 10, 2021, 5:07 p.m.