0

I am sure this must have a solution somewhere here but I really failed to find it. There is something along the same here, but then not really. Say I have a nested list of variable lengths - below length is 2:

L = list('Z1' = c('z11', 'z12'), 'Z2' = c('z21', 'z22', 'z23'))

How do I get in base R all combinations of sublists. For short lists like L one would do for instance:

> expand.grid(L[[1]], L[[2]])
  Var1 Var2
1  z11  z21
2  z12  z21
3  z11  z22
4  z12  z22
5  z11  z23
6  z12  z23

But how is this achieved in the general case ?

user3375672
  • 3,728
  • 9
  • 41
  • 70
  • See https://stackoverflow.com/questions/4233742/permutations-of-a-list-of-lists. Edit: sorry, that's python.. Anyway, what you should search for is how to generate permutations. – Torkel Velure Oct 15 '19 at 21:39
  • @joran Goddamit. (Torkel Velure: year Ihats Python). – user3375672 Oct 15 '19 at 21:41
  • @user3375672 Look at my answer [here](https://stackoverflow.com/questions/58399137/how-to-create-matrix-of-all-2n-binary-sequences-of-length-n-using-recursion-in/58400455#58400455) – slava-kohut Oct 15 '19 at 21:54

0 Answers0