Map()
In this page:
Map()
Map(FUN, x, y, ...) applies a function to corresponding elements of two or more vectors/lists in parallel, similar to zip-and-apply in other languages. Unlike sapply(), which iterates over a single input, Map() is built for combining multiple inputs element-wise. It always returns a list, like lapply().
Note: Map() is how you apply a function across two (or more) vectors in parallel -- sapply()/lapply() only handle a single input vector.
Example: Map()
a <- c(1, 2, 3)
b <- c(10, 20, 30)
result <- Map(function(x, y) x + y, a, b)
print(result)
Login to try C/C++/Java/PHP code in the editor