remapper: Create a function for re-mapping values.

Description Usage Arguments Details Value Author(s) Examples

Description

This is a function factory for creating a function that maps old values to new ones.

Usage

1
remapper(old, new, na_when_missing = TRUE, fun = NULL, ...)

Arguments

old

Vector. The old values.

new

Vector. The new values.

na_when_missing

Logical. If a value cannot be found, should NA be used or value queried for? (defaults to TRUE).

fun

A function applied to the result before returning.

...

Further arguments for fun.

Details

The factory internally uses a hashmap for mapping old to new values. For the possible data types of old and new, consult the documentation of hashmap (Here, keys corresponds to old and values to new).

Value

A vector with re-mapped values.

Author(s)

Domink Mueller (dominikmueller64@yahoo.de)

Examples

1
2
3
4
5
6
old <- letters
new <- toupper(old)
rmp <- remapper(old = old, new = new)
x <- c('a', 'qrz', 'd')
rmp(x)
remapper(old = old, new = new, na_when_missing = FALSE)(x)

DominikMueller64/dmisc documentation built on May 6, 2019, 2:52 p.m.