[R] Expanding upon expand.grid()

Andrew Criswell arc at arcriswell.com
Thu May 8 04:38:48 CEST 2003


Hello All:

The function expand.grid() does nearly exactly what I want for
permutation tests I wish to carry out, and it does so quickly when the
number is kept small as in the example below: 

expand.grid(rep(list(c(-1, 1)), 3))

  Var1 Var2 Var3
1   -1   -1   -1
2    1   -1   -1
3   -1    1   -1
4    1    1   -1
5   -1   -1    1
6    1   -1    1
7   -1    1    1
8    1    1    1

Understandably, for a larger number--16, for example--the grid expands
to a 65,536 x 16 = 1,048,576 element array of numbers.

My question is this: is it possible to compute a grid like the one above
on a row-by-row basis?  What I would like to do is to iteratively take
one row at a time, compute its sum, store the computed sum for the row,
and replace the latest row by the next row. In that way, memory burden
and computation time would be reduced.

Thanks for your help,
ANDREW




More information about the R-help mailing list