Re: [R] Need help optimizing/vectorizing nested loops

2008-12-09 Thread tyler
Charles C. Berry writes: > On Tue, 9 Dec 2008, tyler wrote: > > > I'm analyzing a large number of large simulation datasets, and I've > > isolated one of the bottlenecks. Any help in speeding it up would be > > appreciated. > > Cast the neighborhoods as an indicator matrix, then use matrix

Re: [R] Need help optimizing/vectorizing nested loops

2008-12-09 Thread bartjoosen
Hello, how about changing the last loop to an apply? time.test2 <- function(dat) { cen <- dat grps <- 5 n.rich <- numeric(grps^2) n.ind <- 1 for(i in 1:grps) for (j in 1:grps) { n.cen <- numeric(ncol(cen) - 2) neighbours <- expand.grid(X=(j-1):(j+1), Y=(i-1):(i

Re: [R] Need help optimizing/vectorizing nested loops

2008-12-09 Thread Charles C. Berry
On Tue, 9 Dec 2008, tyler wrote: Hi, I'm analyzing a large number of large simulation datasets, and I've isolated one of the bottlenecks. Any help in speeding it up would be appreciated. Cast the neighborhoods as an indicator matrix, then use matrix multiplications: system.time(tmp <- t

[R] Need help optimizing/vectorizing nested loops

2008-12-09 Thread tyler
Hi, I'm analyzing a large number of large simulation datasets, and I've isolated one of the bottlenecks. Any help in speeding it up would be appreciated. `dat` is a dataframe of samples from a regular grid. The first two columns are the spatial coordinates of the samples, the remaining 20 columns