Skip to content

Instantly share code, notes, and snippets.

@Keiku
Last active February 20, 2017 07:12
Show Gist options
  • Save Keiku/f71ea2e61a97c2343fa280ad31f034fe to your computer and use it in GitHub Desktop.
Save Keiku/f71ea2e61a97c2343fa280ad31f034fe to your computer and use it in GitHub Desktop.
Extract a set from the multiple vectors.
a <- c(1, 3, 5, 7, 9)
b <- c(3, 6, 8, 9, 10)
c <- c(2, 3, 4, 5, 7, 9)
intersect_all <- function(...) Reduce(intersect, list(...))
union_all <- function(...) Reduce(union, list(...))
intersect_all(a, b, c)
# [1] 3 9
union_all(a, b, c)
# [1] 1 3 5 7 9 6 8 10 2 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment