I would like to get a matrix that contains all $2^p$ combinations of $p$ binary variables. It feels like something that should be a one-liner but I can't seem to find this.
Asked
Active
Viewed 238 times
1 Answers
0
OK, found it:
p <- 3
l <- rep(list(0:1), p)
expand.grid(l)
From here: Generate list of all possible combinations of elements of vector

jmb
- 625
- 7
- 11