Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 查找1和k之间n个数字的所有唯一组合_R_Combinations - Fatal编程技术网

R 查找1和k之间n个数字的所有唯一组合

R 查找1和k之间n个数字的所有唯一组合,r,combinations,R,Combinations,我想要一个由5个(或n个)数字组成的列表,这些数字在1和63之间(或者更概括地说是1和k) 如果计算时间不是问题的话,我可以这样做 #Get all combenations of numbers between 1 and 63 indexCombinations <- expand.grid(1:63, 1:63, 1:63, 1:63, 1:63) #Throw out the rows that have more than one of the same number i

我想要一个由5个(或n个)数字组成的列表,这些数字在1和63之间(或者更概括地说是1和k)

如果计算时间不是问题的话,我可以这样做

 #Get all combenations of numbers between 1 and 63
 indexCombinations <- expand.grid(1:63, 1:63, 1:63, 1:63, 1:63)

 #Throw out the rows that have more than one of the same number in them
 allDifferent <- apply(indexCombinations, 1, function(x){
      length(x) == length(unique(x))
 } # function
 ) # apply

 indexCombinationsValid <- indexCombinations[allDifferent,]

 # And then just take the unique values
 indexCombinationsValidUnique <- unique(indexCombinationsValid)
#获取1到63之间的所有数字组合

indexCombinations感谢@SymbolXau提供了一个非常优雅的解决方案,我在这里重新发布了这个解决方案,作为一个答案:

 n <- 1:63; x <- combn(n, m = 5)

这就是你要尝试的:
n是的。这就是我要找的。