mapping | R Documentation |
This function returns a function that does a simple mapping from one set of value to another. It is a function-generating function.
mapping(from, to, ch.as.fact = TRUE)
from |
A vector. This is the domain of the function. |
to |
A vector of the same length as |
ch.as.fact |
A logical. Should the mapping return a
|
This function returns a function. When called with a vector
argument x
, this function will return a vector y
of
the same length as x
and such that each element y[i]
is equal to to[j]
where j
is the smallest integer such
that from[j] == x[i]
, and NA
if no such j
exists.
A function that translates from from
to to
. The
function also has a attribute "inverse"
which is a function
that performs the inverse mapping.
Benjamin Rich <mail@benjaminrich.net>
sex.mapping <- mapping(c("Female", "F", "Male", "M"), c(0, 0, 1, 1))
sex.mapping(c("Female", "Female", "Male", "F"))
sex.inverse.mapping <- attr(sex.mapping, "inverse")
sex.inverse.mapping(c(0, 0, 1, 0))
race.mapping <- mapping(c(1, 2, 5), c("WHITE", "BLACK OR AFRICAN AMERICAN", "AMERICAN INDIAN OR ALASKA NATIVE"))
race.mapping(1:5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.