0

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.

jmb
  • 625
  • 7
  • 11

1 Answers1

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