2016-12-27 39 views
2

數據幀假設我們有以下列表:R:從排列

L <- list(c(1, 1), c(2, 2), c(3, 3)) 

我要找的L所有可能的獨特的基因重組,無需更換(即排列)。

結果應該是一個數據幀,包含factorial(length(L))的行數和length(L)*2的列數。在我們的例子,ncol = 3*2nrow = 3!

allPossibleCombinations(L) 

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

回答

2

我們可以使用permncombinat

library(combinat) 
m1 <- t(sapply(permn(L), unlist)) 
+1

這正是我一直在尋找。謝謝。 – mat