Skip to content

Instantly share code, notes, and snippets.

@HarlanH
Created September 28, 2010 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HarlanH/601364 to your computer and use it in GitHub Desktop.
Save HarlanH/601364 to your computer and use it in GitHub Desktop.
# solution via Hadley Wickham and others at:
# http://www.mail-archive.com/r-help@stat.math.ethz.ch/msg85203.html
qq <- list(data.frame(c1=c('a', 'b', 'c')), data.frame(c1=c('a','d','e')), data.frame(c1=c('a','f','g')))
fold <- function(x, fun) {
if (length(x) == 1) return(fun(x))
accumulator <- fun(x[[1]], x[[2]])
if (length(x) == 2) return(accumulator)
for(i in 3:length(x)) {
accumulator <- fun(accumulator, x[[i]])
}
accumulator
}
fold(lapply(qq, function(df) df$c1), intersect)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment