Hi, I have: i = c(1,2,3) j = c(4,5,6) How do I create a matrix of all pairs? i.e. 1,4 1,5 1,6 2,4 : Thanks! -- View this message in context: http://www.nabble.com/How-to-create-all-pairs-tp23714659p23714659.html Sent from the R help mailing list archive at Nabble.com.
Dear alad, Try this: expand.grid(i,j) See ?expand.grid for more details. HTH, Jorge On Mon, May 25, 2009 at 7:26 PM, alad <abhimanyulad@gmail.com> wrote:> > Hi, > > I have: > i = c(1,2,3) > j = c(4,5,6) > > How do I create a matrix of all pairs? > i.e. > 1,4 > 1,5 > 1,6 > 2,4 > : > > Thanks! > > > -- > View this message in context: > http://www.nabble.com/How-to-create-all-pairs-tp23714659p23714659.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Is this what you want:> i = c(1,2,3) > j = c(4,5,6) > expand.grid(i,j)Var1 Var2 1 1 4 2 2 4 3 3 4 4 1 5 5 2 5 6 3 5 7 1 6 8 2 6 9 3 6>On Mon, May 25, 2009 at 7:26 PM, alad <abhimanyulad@gmail.com> wrote:> > Hi, > > I have: > i = c(1,2,3) > j = c(4,5,6) > > How do I create a matrix of all pairs? > i.e. > 1,4 > 1,5 > 1,6 > 2,4 > : > > Thanks! > > > -- > View this message in context: > http://www.nabble.com/How-to-create-all-pairs-tp23714659p23714659.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]
?expand.grid e.g. M <- expand.grid(i = 1:3, j = 4:6) You can coerce it to a matrix if that is really what you want. Bill Venables http://www.cmis.csiro.au/bill.venables/ -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of alad Sent: Tuesday, 26 May 2009 9:27 AM To: r-help at r-project.org Subject: [R] How to create all pairs Hi, I have: i = c(1,2,3) j = c(4,5,6) How do I create a matrix of all pairs? i.e. 1,4 1,5 1,6 2,4 : Thanks! -- View this message in context: http://www.nabble.com/How-to-create-all-pairs-tp23714659p23714659.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.
expand.grid(i,j) On Mon, May 25, 2009 at 8:26 PM, alad <abhimanyulad at gmail.com> wrote:> > Hi, > > I have: > i = c(1,2,3) > j = c(4,5,6) > > How do I create a matrix of all pairs? > i.e. > 1,4 > 1,5 > 1,6 > 2,4 > : > > Thanks! > > > -- > View this message in context: http://www.nabble.com/How-to-create-all-pairs-tp23714659p23714659.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. >-- Mike Lawrence Graduate Student Department of Psychology Dalhousie University Looking to arrange a meeting? Check my public calendar: http://tr.im/mikes_public_calendar ~ Certainty is folly... I think. ~