对的排列列表

编程入门 行业动态 更新时间:2024-10-27 19:28:03
本文介绍了对的排列列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我敢肯定,对你们许多人来说,这很简单,这将挽救我的生活:我需要生成一系列数字的所有对的置换集.例如,对于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 #...

更多推荐

对的排列列表

本文发布于:2023-11-29 22:15:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647783.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:排列   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!