Description Arguments Value Usage Details Note Author(s) References See Also Examples
This function implements a map operation over arbitrary indexable data structures. Both 1D and 2D data structures are supported.
x |
Any indexable data structure |
fn |
A function applied to each x_i in x |
acc |
An initial data structure to accumulate the value of f(x_i) |
A sequence representing < f(x_i) > for all x_i in x
map(x, fn, acc) %::% . : Function : . : .
map(x, fn, acc=c())
While many functions in R are vectorized, some functions only work for scalar input. The map function transforms any scalar-valued function into a vectorized function. This is known as the map-equivalent form of the scalar function.
The map operation is implemented for 2D data structures as a column-based operation. If a row-based procedure is desired instead, simply transpose the data structure.
Conceptually, the map operation is equivalent to the apply family of functions. The reason for this implementation is primarily for pedagogical purposes.
This function is implemented using recursion and will
throw an error if the length of x
approaches
getOption('expressions') / 8.0
. This limit
is due to R attempting to protect against infinite recursion.
See options
for more details.
Brian Lee Yung Rowe
Rowe, Brian Lee Yung. Modeling Data With Functional Programming In R. Chapman & Hall/CRC Press. Forthcoming.
1 2 3 4 5 6 7 8 9 10 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.