在R中生成非重复组合对 [英] Generating non-duplicate combination pairs in R

查看:72
本文介绍了在R中生成非重复组合对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉使用非描述性标题,但我不知道我要达到的目标。

Sorry for the non-descriptive title but I don't know whether there's a word for what I'm trying to achieve.

让我们假设我有一个

c( '1', '2', '3', '4')

我想从中生成所有可能的排列对,以便没有反向重复。所以我想拥有的是这样的东西

I'd like to generate all possible permutation pairs out of this so that there are no reverse-duplicates. So what I'd like to have is something like

'1' '2'
'1' '3'
'1' '4'
'2' '3'
'2' '4'
'3' '4'

请注意,我没有例如'2''1',因为我已经有'1''2'

Note that I don't have e.g. '2' '1' because I already have '1' '2'. Is there an easy way to achieve this in R?

推荐答案

> x<-c('1','2','3','4')
> combn(x,2)
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,] "1"  "1"  "1"  "2"  "2"  "3" 
[2,] "2"  "3"  "4"  "3"  "4"  "4"

这篇关于在R中生成非重复组合对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆