[R] Combining elements of vectors

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Mon Jun 8 15:03:17 CEST 2009


one way is:

combn(c("a", "b", "c"), 2)


I hope it helps.

Best,
Dimitris


Marie Sivertsen wrote:
> Dear list,
> 
> I have a vector of elements which I want to combined each with each, but
> none with itself. For example,
> 
>> v <- c("a", "b", "c")
> 
> and I need a function 'combine' such that
> 
>> combine(v)
> [[1]]
> [1] "a" "b"
> 
> [[2]]
> [1] "a" "b"
> 
> [[3]]
> [1] "b" "c"
> 
> I am not very interested in the orders of the output items for now, and the
> form can be something differs from list, like matrix or data frame. I know
> of 'expand.grid', but it will combine each item with each item including
> itself, so not what I wants.
> 
> Could you help me please.  Thank you.
> 
> Mvh.,
> Marie
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014




More information about the R-help mailing list