Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vincentarelbundock/204cf658043be43620c005bf584fdb27 to your computer and use it in GitHub Desktop.
Save vincentarelbundock/204cf658043be43620c005bf584fdb27 to your computer and use it in GitHub Desktop.
library(tidyverse)
example <- tibble(id = 1:500,
A = sample(TRUE:FALSE, 500, replace = TRUE),
B = sample(TRUE:FALSE, 500, replace = TRUE),
C = sample(TRUE:FALSE, 500, replace = TRUE),
D = sample(TRUE:FALSE, 500, replace = TRUE),
E = sample(TRUE:FALSE, 500, replace = TRUE),
F = sample(TRUE:FALSE, 500, replace = TRUE))
check_combinations <- function(m = 5) {
com <- colnames(example)[2:ncol(example)] %>%
combn(m) %>%
as_tibble
out <- com %>%
map(~ example[.]) %>%
map(~ rowSums(.) == ncol(.)) %>%
setNames(map(com, paste, collapse = ' + ')) %>%
as_tibble
return(out)
}
result <- map(2:6, check_combinations) %>%
bind_cols(example, .)
result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment