map: Map One Set of Values to Another

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Systematically substitute specific values from one set using corresponding values from another set.

Usage

1
map(x, from, to, strict=TRUE, ...)

Arguments

x

vector

from

vector (elements usually unique)

to

vector with same length as from

strict

whether to set unmapped values to NA (default)

...

ignored

Details

Occasionally one wants to recode a set of categories using some other idiom. factor supports recoding by creative use of the arguments levels and labels. However, the result is a factor, and may need more transformation. Furthermore, factor allows one-to-one reclassification but not many-to-one reclassification (repeated levels is not supported; i.e., it is not directly possible to collapse two levels to a single replacement code).

Here, from is the discrete set of values we expect in x, and to is the element-wise corresponding values with which we wish to re-present elements in x. Values in x not found in from will be normally represented as NA (which is itself a legitimate value for to). However, if strict=FALSE, map tries to preserve un-mapped values.

It is an error if from and to have different lengths.

Value

vector of same class as to and same length as x

Author(s)

Tim Bergsma

References

http://metrumrg.googlecode.com

See Also

Examples

1
2
3
4
5
map(
	c('white','Asian','Indian'),
	from=c('white','White','black','Black','asian','Asian'),
	to=  c(   1,      1,      2,      2,      3,      3   )
)

metrumrg documentation built on May 2, 2019, 5:55 p.m.