[R] How to make a cartesian pairlist from a vector?

newbyr arielah at amgen.com
Mon Nov 23 21:54:34 CET 2009


This is very helpful. Thank you very much.


Charles C. Berry wrote:
> 
> On Fri, 20 Nov 2009, newbyr wrote:
> 
>>
>> Hi,
>>
>> I'm looking for a function that will take a list of columns or data.frame
>> and corvert it to cartesian pairlist. For example for this data.frame
>> (see
>> below), I'd like to get a list of all possible pairs:
>>
>>> sound
>>  cs rs ns
>>  7  5  2
>>  4  5  4
>>  6  3  1
>>  8  4  1
>>  6  4  2
>>  6  7  1
>>  2  2  5
>>  9  2  5
>>
> 
>> how can I get this?
>>> mylist
>>  ((cs,rs), (cs,ns), (rs,ns))
> 
>  	str(combn(colnames(df),2,function(x) df[,x],simplify=F))
> 
> see
> 
>  	?combn
> 
> HTH,
> 
> Chuck
> 
> p.s. Following the posting guide's hints you might try
> 
> ?combinations  # no go, but it says try ??combinations
> ??combinations # shows utils:combn
> ?combn #  bingo!
> 
> 
> 
> 
>>
>> This list contains a set of all possible combinations of column pairs.
>>
>> Thank you for your help.
>>
>> -- 
>> View this message in context:
>> http://old.nabble.com/How-to-make-a-cartesian-pairlist-from-a-vector--tp26452861p26452861.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>>
> 
> Charles C. Berry                            (858) 534-2098
>                                              Dept of Family/Preventive
> Medicine
> E mailto:cberry at tajo.ucsd.edu	            UC San Diego
> http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-make-a-cartesian-pairlist-from-a-vector--tp26452861p26485572.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list