mapply adalah versi multivariat dari sapply. mapply menerapkan FUN pada elemen pertama dari setiap… argumen, elemen kedua, elemen ketiga, dan seterusnya. Argumen didaur ulang jika perlu.
mapply(FUN, …, MoreArgs = NULL, SIMPLIFY = TRUE,
USE.NAMES = TRUE)
| Parameter | Deskripsi |
|---|---|
FUN |
function to apply, found via match.fun. |
… |
arguments to vectorize over (vectors or lists of strictly positive length, or all of zero length). See also ‘Details’. |
MoreArgs |
a list of other arguments to FUN. |
SIMPLIFY |
logical or character string; attempt to reduce the result to a vector, matrix or higher dimensional array; see the simplify argument of sapply. |
USE.NAMES |
logical; use names if the first … argument has names, or if it is a character vector, use that character vector as the names. |
# NOT RUN {
mapply(rep, 1:4, 4:1)
mapply(rep, times = 1:4, x = 4:1)
mapply(rep, times = 1:4, MoreArgs = list(x = 42))
mapply(function(x, y) seq_len(x) + y,
c(a = 1, b = 2, c = 3), # names from first
c(A = 10, B = 0, C = -10))
word <- function(C, k) paste(rep.int(C, k), collapse = "")
utils::str(mapply(word, LETTERS[1:6], 6:1, SIMPLIFY = FALSE))
# }