I was interested in looking at doing some computations for a bunch of variables whose values were all either 1 or 2.
I was trying to set this up with something like expand grid.
Ideally I could get 10+ columns (column names don't matter).
If I were to do this manually for 3 columns, it'd look something like
df <- expand.grid(a=1:2, b=1:2, c=1:2,)
but this somehow feels inelegant.
I tried using
df <- expand.grid(rep(1:2, 3))
But this produced a single column where the numbers 1 and 2 were repeated 3 times, instead of a grid.
Is there a way to get expand.grid
to work with my input, or is there an easy way of doing what I'm asking for using another method?