R - Reduce(): combine values of vectors by applying a function

14 Aug 2019

Reduce() uses a binary function to successively combine the elements of a given vector and a possibly given initial value.

Example: Reduce(f = “+”, x) is the same as x[[[1]] + … + x[[n]]

mylist = list(c("a", "b", "c"), c("a", "z", "x"), c("y", "d", "a"))
Reduce(intersect, mylist)
# [1] "a"
[ R  function  list  ]