Re: [R] Puzzled at generating combinations

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Wed, 19 Mar 2008 09:45:50 +0100

Or he can use expand grid

expand.grid(paste("r",1:3, sep=""), paste("R", 1:3, sep=""))

Petr Pikal
petr.pikal_at_precheza.cz

r-help-bounces_at_r-project.org napsal dne 18.03.2008 17:15:54:

> > I have two data frames. Suppose the first has rows
> >
> > r1
> > r2
> > r3
> >
> > and the second has rows
> >
> > R1
> > R2
> > R3
> >
> > I'd like to generate the data frame:
> >
> > r1 R1
> > r1 R2
> > r1 R3
> > r2 R1
> > r2 R2
> > r2 R3
> > r3 R1
> > r3 R2
> > r3 R3
>
> Try:
> col1 <- paste("r", 1:3, sep="")
> col2 <- paste("R", 1:3, sep="")
> data.frame(rep(col1, each=3), rep(col2, times=3))
>
> Regards,
> Richie.
>
> Mathematical Sciences Unit
> HSL
>
>
> ------------------------------------------------------------------------
> ATTENTION:
>
> This message contains privileged and confidential
inform...{{dropped:20}}
>
> ______________________________________________
> R-help@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. Received on Wed 19 Mar 2008 - 08:49:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 19 Mar 2008 - 10:30:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive