-----Original Message-----
From: Yves Brostaux [mailto:brostaux.y at fsagx.ac.be]
Sent: Wednesday, May 28, 2003 4:30 AM
To: r-help at stat.math.ethz.ch
Subject: [R] Slow computation in for loop
Dear members,
I'm using R to do some test computation on a set of parameters of a
function. This function is included in three for() loops,
first one for
replications, and the remaining two cycling through possible
parameters
values, like this :
for (k in replicates) {
data <- sampling from a population
for (i in param1) {
for (j in param2) {
result <- function(i, j, data)
}
}
}
With the 'hardest' set of parameters, a single computation of
the function
take about 16s on an old Sun Sparc workstation with 64 Mb RAM
and don't
access a single time to disk.
But when I launch the for() loops (which generate 220
function calls), disk
gets very sollicitated and the whole process takes as much as 8 to 10
hours, instead of the expected 1 hour.
What's wrong here ? Is there a thing I don't know about for()
loops, and a
way to correct it ?