[R] Advice on long for loop

Agustin Lobo alobo at ija.csic.es
Fri Dec 13 15:12:03 CET 2002


I'd appreciate advice on the following:

I've written an R function
that uses 3 vectors (temperature,
precipitation and potential evapotranspiration)
for a given site, calculates a water budget
(which implies few (<4) iterations), and, from
thresults of this water budget, calculates a number of
bioclimatic indices.

Now I want to calculate these indices
for a large number of sites (arranged
as cells in a raster map),  using
monthly raster maps (m rows x n cols)  of temperature,
precipitation and potential evapotranspiration.

I do not see any other way than using
two nested for loops and calling the
aforementioned function for each cell in the
map. But this would be a problem in R
as m and n can be ~ 500.

My question is: would it be any better if
I write a simple python function with the loops
and call the R function for each cell (using
the R-Python interface)? Or, as the calculation
in each cell is independent, should I rather write a
shell script with the loop and submit jobs
with R CMD BATCH?

Thanks

Agus

Dr. Agustin Lobo
Instituto de Ciencias de la Tierra (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona SPAIN
tel 34 93409 5410
fax 34 93411 0012
alobo at ija.csic.es




More information about the R-help mailing list