来自不同容器的元素的所有可能组合(每个容器中的一个元素)

All possible combinations of elements from different bins (one element from every bin)

我有一个列表,其中每个元素都是一组数字。所有组的长度都不同:

 a <- list(1,c(2,3),c(4,5,6))
#> a
#[[1]]
#[1] 1

#[[2]]
#[1] 2 3

#[[3]]
#[1] 4 5 6 

我想从每个集合中获取一个元素的所有可能组合。在这个例子中它应该是:

1 2 4、1 2 5、1 2 6、1 3 4、1 3 5、1 3 6

我觉得这里 *apply-functions 的某种组合会很有用,但不知道该怎么做。

我们可以使用expand.grid

expand.grid(a)