r - Generate list of all possible combinations of elements of vector -


i trying generate possible combinations of 0 , 1's in vector of length 14. there easy way of getting output list of vectors, or better, dataframe?

to demonstrate better looking for, let's suppose want vector of length 3. able generate following:

 (1,1,1), (0,0,0), (1,1,0), (1,0,0), (1,0,1), (0,1,0), (0,1,1), (0,0,0) 

any appreciated!

thanks,

you're looking expand.grid.

expand.grid(0:1, 0:1, 0:1) 

or, long case:

n <- 14 l <- rep(list(0:1), n)  expand.grid(l) 

Comments