[R] Pairwise combination

Ista Zahn istazahn at gmail.com
Tue May 11 22:33:57 CEST 2010


combn(1:4, 2) will do it.

-Ista

On Tuesday 11 May 2010 1:45:14 pm chen jia wrote:
> Hi there,
> 
> I am looking for a function that takes a vector as input and generates
> all pair wise combination of the elements of the input vector.
> 
> For example, the input vector is c(1,2,3,4). The output vector is c(1
> and 2, 1 and 3, 1 and 4, 2 and 3, 2 and 4, 3 and 4). The
> representation here is generic.
> 
> I can use a for loop to do it, but it gets slow when the number of
> elements of the input vector is large.
> 
> Best,
> Jia



More information about the R-help mailing list