Filter(f, x) Find(f, x, right = FALSE, nomatch = NULL) Map(f, ...) Negate(f) Reduce(f, x, init, right = FALSE, accumulate = FALSE) Position(f, x, right = FALSE, nomatch = NA_integer_)
f | a function to be applied to x. f contains only one argument for Filter, Find and Position. It contains two arguments for Reduce. It contains more arguments for Map (depending on the ... argument). For Negate, f must return a logical value. |
x | any vector, matrix, or list object to which to apply f. |
right | a logical value. If TRUE, the operation is performed from right to left. If FALSE (the default), the operation is performed from left to right. |
nomatch | the value to return when there is no match for Find and Position. |
init | the initial value for which to apply Reduce. If init is missing, the first element or the last element (if right is TRUE) of x is used as the initial value. |
accumulate | a logical value. If TRUE, the accumulated results of each Reduce step are returned. If FALSE (the default), only the result of the last Reduce step is returned. |
... | More arguments like x. |
Filter | returns a subset of x. |
Find | returns the first matched element of x, or the specified value for nomatch. |
Position | returns an integer of the position of the matched element of x, or the specified value for nomatch. |
Map | returns a list, vector, or matrix, which is the return value of mapply(f, ..., SIMPLIFY = FALSE). |
Negate | returns a logical value. |
Reduce | returns the combination of last reduce step, or the accumulated combinations of each reduce step, in a vector. |
# Filter out non-positive values in sin(1:10) Filter(function(x) x > 0, sin(1:10))
# Find the first non-zero result of "sin(x)" from left to right Find(sin, c(0, -1, 0, -2, 1, 4))
# Find the first non-zero result of "sin(x)" from right to left Find(sin, c(0, -1, 0, -2, 1, 4), right = TRUE)
# Find the position of first non-zero result of "sin(x)" from left # to right Position(sin, c(0, -1, 0, -2, 1, 4))
# Find the position of first non-zero result of "sin(x)" from right to left Position(sin, c(0, -1, 0, -2, 1, 4), right = TRUE)
unlist(Map(function(str)max(strsplit(str,split="")[[1]]), month.abb))
Negate(is.na)(c(1, 2, 3, NA, 4, 5, NA_integer_, 7))
Reduce("+", c(1, 4, -1, 3, 2, 0, 5)) Reduce("+", c(1, 4, -1, 3, 2, 0, 5), accumulate = TRUE)