Skip to content

All possible pairs of two variables

5 messages · Ron Michael, Yihui Xie, Matthias Kohl +1 more

#
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:

  
    
#
take a look at the code of the function pairwise.table. It shows a way 
using function outer.

hth,
Matthias
Yihui Xie wrote:

  
    
#
On Wed, Sep 10, 2008 at 11:34 PM, Ron Michael <ron_michael70 at yahoo.com> wrote:
?expand.grid

Hadley
#
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:
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: