本文介绍了对的排列列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我敢肯定,对你们许多人来说,这很简单,这将挽救我的生活:我需要生成一系列数字的所有对的置换集.例如,对于1:6,它将得到30个子集,即n(n-1):
An easy one for many of you, I'm sure, which will save my day : I need to generate a permutation set of all the pairs of a sequence of numbers. For example, for 1:6, it will give as a final result, 30 subsets, i.e. n(n-1) :
(1,2),(3,4),(5,6) ... (1,6),(2,3),(4,5)我需要一对,而不是一对,所以(3,4)和(4,3)是唯一的一对.
I need pairs, not couples, so that (3,4) and (4,3) is an unique pair.
combn(1:6,2)给了我一张表格,其中以配对为列,但是如何从中产生配对列表呢?
combn(1:6,2) gives me a table with my pairs as columns, but how do I produce my list of pairs out of it?
combn(1:6,2) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [1,] 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5 [2,] 2 3 4 5 6 3 4 5 6 4 5 6 5 6 6谢谢
推荐答案我们可以在 combn 中设置参数 simplify = FALSE ,使其返回列表:
We can set the argument simplify = FALSE in combn such that it returns a list:
combn(1:6, 2, simplify = FALSE) #[[1]] #[1] 1 2 # #[[2]] #[1] 1 3 # #[[3]] #[1] 1 4 # #[[4]] #[1] 1 5 #...更多推荐
对的排列列表
发布评论