[R] stacking effectively - without loops

Johannes Huesing johannes at huesing.name
Tue Nov 2 22:04:00 CET 2010


Dimitri Liakhovitski <dimitri.liakhovitski at gmail.com> [Tue, Nov 02, 2010 at 09:57:04PM CET]:
> Hello!
> 
> I have 2 vectors:
> 
> x<-letters[1:5]
> y<-1:3
> 
> Is there a way - without loops - to create a data frame such that we
> repeat the whole "y" within each level of "x" so that it looks like
> this:
> 
> a 1
> a 2
> a 3
> b 1
> b 2
> b 3
> c 1
> c 2
> c 3
> 
> etc?

?expand.grid


-- 
Johannes Hüsing               There is something fascinating about science. 
                              One gets such wholesale returns of conjecture 
mailto:johannes at huesing.name  from such a trifling investment of fact.                
http://derwisch.wikidot.com         (Mark Twain, "Life on the Mississippi")



More information about the R-help mailing list