[R] Generate strings from multiple variables

Bert Gunter gunter.berton at gene.com
Fri May 4 16:59:24 CEST 2012


?outer

Bert

Sent from my iPhone -- please excuse typos.

On May 4, 2012, at 6:25 AM, "R. Michael Weylandt" <michael.weylandt at gmail.com> wrote:

> do.call(function(x,y) paste0("A",x,"_","B",y),expand.grid(x = A,y = B))
> 
> seems to be a place to start. Robust generalization seems a hair
> tricky -- I'll mull on it.
> 
> Michael
> 
> On Fri, May 4, 2012 at 9:10 AM, Johannes Radinger <JRadinger at gmx.at> wrote:
>> Hi,
>> 
>> it is easiest to explain what I want to do by an example:
>> 
>> lets assume there are two factors/variables:
>> A <- c(1,2,3)
>> B <- c(1,3,3)
>> 
>> Now I would like to generate a list of strings that should look like
>> ("A1_B1","A1_B2","A2_B1","A2_B2"). So actually the string
>> contains all possible combinations of A and B (separated by _). This should
>> be also possible for more variables. Is there simple way
>> to that? I thought about looping over A and B (nested for-loop)
>> but maybe there is a straight foward solution to get such strings.
>> 
>> /johannes
>> 
>> 
>> --
>> 
>> Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
>> 
>> ______________________________________________
>> 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.
> 
> ______________________________________________
> 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.



More information about the R-help mailing list