[R] Expanding upon expand.grid()
Robin Hankin
r.hankin at auckland.ac.nz
Thu May 8 05:07:47 CEST 2003
Andrew
as.binary <- function(n){if(n==0){return(NULL)
} else {
return(c((n%%2),Recall(as.integer(n/2))))}}
might help.
rksh
>
> 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
--
Robin Hankin, Lecturer,
School of Geography and Environmental Science
Tamaki Campus
Private Bag 92019 Auckland
New Zealand
r.hankin at auckland.ac.nz
tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042
More information about the R-help
mailing list