tags:

views:

279

answers:

1

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

Let's assume that I have a list of names of different classes like

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'

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?

+5  A: 
> 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"
Mark
Seems nice and simple. I was right thinking there was something like this. Thanks.
lhahne