I have two variables (x,y) : x : it takes all integer values from 0 to y and, y : takes all values from 0, 10 I am looking for some R code to find all possible pairs of (x,y). Can anyone please help me? New Email addresses available on Yahoo! Get the Email name you've always wanted on the new @ymail and @rocketmail. Hurry before someone else does! [[alternative HTML version deleted]]
Just simple loops as follows: ######################## z = NULL for (y in 0:10) { for (x in 0:y) { z = rbind(z, c(x, y)) } } z ######################## Yihui On Thu, Sep 11, 2008 at 12:34 PM, Ron Michael <ron_michael70 at yahoo.com> wrote:> I have two variables (x,y) : > > x : it takes all integer values from 0 to y and, > y : takes all values from 0, 10 > > I am looking for some R code to find all possible pairs of (x,y). Can anyone please help me? > > >-- Yihui Xie <xieyihui at gmail.com> Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China
take a look at the code of the function pairwise.table. It shows a way using function outer. hth, Matthias Yihui Xie wrote:> Just simple loops as follows: > > ######################## > z = NULL > for (y in 0:10) { > for (x in 0:y) { > z = rbind(z, c(x, y)) > } > } > z > ######################## > > Yihui > > On Thu, Sep 11, 2008 at 12:34 PM, Ron Michael <ron_michael70 at yahoo.com> wrote: > >> I have two variables (x,y) : >> >> x : it takes all integer values from 0 to y and, >> y : takes all values from 0, 10 >> >> I am looking for some R code to find all possible pairs of (x,y). Can anyone please help me? >> >> >> >> > >-- Dr. Matthias Kohl www.stamats.de
On Wed, Sep 10, 2008 at 11:34 PM, Ron Michael <ron_michael70 at yahoo.com> wrote:> I have two variables (x,y) : > > x : it takes all integer values from 0 to y and, > y : takes all values from 0, 10 > > I am looking for some R code to find all possible pairs of (x,y). Can anyone please help me??expand.grid Hadley -- http://had.co.nz/
But x is from 0 to "y" instead of a fixed number (say, 10)... If we are to use expand.grid(), we should filter out half of rows in the result:> z = expand.grid(0:10, 0:10) > z[z[,1] <= z[,2], ]Var1 Var2 1 0 0 12 0 1 13 1 1 23 0 2 24 1 2 25 2 2 34 0 3 35 1 3 36 2 3 37 3 3 .... Yihui On Thu, Sep 11, 2008 at 8:53 PM, hadley wickham <h.wickham at gmail.com> wrote:> On Wed, Sep 10, 2008 at 11:34 PM, Ron Michael <ron_michael70 at yahoo.com> wrote: >> I have two variables (x,y) : >> >> x : it takes all integer values from 0 to y and, >> y : takes all values from 0, 10 >> >> I am looking for some R code to find all possible pairs of (x,y). Can anyone please help me? > > ?expand.grid > > Hadley > > -- > http://had.co.nz/ >-- Yihui Xie <xieyihui at gmail.com> Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China