Last active
June 13, 2019 01:37
-
-
Save vincentarelbundock/204cf658043be43620c005bf584fdb27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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