Re: [R] alternate storage options

From: Moshe Olshansky <m_olshansky_at_yahoo.com>
Date: Thu, 20 Dec 2007 16:20:05 -0800 (PST)


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
}

>
> 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.
>



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. Received on Fri 21 Dec 2007 - 00:24:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 21 Dec 2007 - 00:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.