[R] Recursive concatenation

Marc Schwartz marc_schwartz at comcast.net
Thu Sep 6 17:55:17 CEST 2007


Or:

> sort(levels(interaction(LETTERS[1:3], 1:3, sep = "")))
[1] "A1" "A2" "A3" "B1" "B2" "B3" "C1" "C2" "C3"


Marc

On Thu, 2007-09-06 at 11:46 -0400, Liaw, Andy wrote:
> Or something like:
> 
> R> do.call(paste, c(expand.grid(LETTERS[1:3], 1:3), sep=""))
> [1] "A1" "B1" "C1" "A2" "B2" "C2" "A3" "B3" "C3"
> 
> (The ordering is bit different, but that shouldn't matter.)
> 
> Andy 
> 
> From: Dimitris Rizopoulos
> > try this:
> > 
> > paste(rep(LETTERS[1:3], each = 3), 1:3, sep = "")
> > 
> > 
> > Best,
> > Dimitris
> > 
> > 
> > Quoting Dennis Fisher <fisher at plessthan.com>:
> > 
> > > Colleagues,
> > >
> > > I want to create the following array:
> > > 	"A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"
> > >
> > > I recall that there is a trick using "c" or "paste" permitting me to
> > > form all combinations of c("A", "B", "C") and 1:3.  But, I can't
> > > recall the trick.
> > >
> > > Dennis
> > >



More information about the R-help mailing list