Description Usage Arguments Value Author(s) References See Also Examples
View source: R/list_reduction.R
Successively applies a function (intersect
, by default) to elements
at each index level in a list
.
1 2 3 4 5 6 7 | list_reduction(
inlist,
FUN = intersect,
flatten = FALSE,
sorted = FALSE,
MoreArgs = NULL
)
|
inlist |
The input |
FUN |
The function to be applied. Note that the supplied function should be one
that you would expect to have work with two or more |
flatten |
Logical. Should the output be simplified from a |
sorted |
Logical. Should the values at each |
MoreArgs |
A |
A list
(default) or a simple vector
(if flatten = TRUE
).
Ananda Mahto
See: https://stackoverflow.com/q/62454705/1270695
base::Reduce()
, base::mapply()
1 2 3 4 5 6 7 8 9 10 11 12 13 | L <- list(colA = list(c("a", "b", "c", "ñ"), c("f", "g", "h"), c("i", "j", "k")),
colB = list(c("d", "b", "e"), c("f", "g", "m", "p"), c("f", "o", "j")),
colC = list(c("a", "b", "g"), c("l", "g", "f", "k", "h"), c("j", "o", "l")))
list_reduction(L)
list_reduction(L, flatten = TRUE)
set.seed(1)
L2 <- replicate(3, replicate(3, sample(sample(20), sample(10), TRUE), FALSE), FALSE)
list_reduction(L2)
list_reduction(L2, sum, flatten = TRUE)
list_reduction(L2, range)
list_reduction(L2, union)
list_reduction(L2, union, sorted = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.