[R] alternate storage options

Moshe Olshansky m_olshansky at yahoo.com
Fri Dec 21 01:20:05 CET 2007


You can use a loop...

If x,y and z are your vectors containing Nx,Ny and Nz
numbers respectively, then
for (Ix in 1:Nx) for (Iy in 1:Ny) for (Iz in 1:Nz) {
Point <- c(x[Ix],y[Iy],z[Iz])
do whatever you need with Point
}

A (probably better) compromise may be:

a <- matrix(0,nrow = Ny*Nz, ncol = 3)
for (i in 1:Nx) {
a[,2:3] <- expand.grid(y,z)
a[,1] <- x[i]
do whatever you want with a
}

--- dxc13 <dxc13 at health.state.ny.us> wrote:

> 
> useR's.
> 
> I am working with an algorithm in which I will need
> to create combinations
> of all the points I have in a matrix.  When I have 2
> variables, I simply use
> expand.grid() to do this.  Sometimes I am faced with
> 3 or more variables and
> if I run expand.grid(), R cannot process it due to
> the huge size.  Is there
> any efficient way to workaround this? 
> 
> Thanks,
> Derek
> -- 
> View this message in context:
>
http://www.nabble.com/alternate-storage-options-tp14438736p14438736.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.
>



More information about the R-help mailing list