[R-sig-Geo] daily precipitation idw & kriging and beginner questions

Tom Gottfried tom.gottfried at wzw.tum.de
Wed Aug 19 14:53:45 CEST 2009


Hi Ivan,

> I use a for-loop to go through the columns (the days) and each loop
> performs an idw and autokrige interpolation, plots images and saves them
> as jpg to hard disk.
...
> Also, is there another method to deal with the results, for
> instance can I create an object Pd.idw.many which contains all of the 31
> interpolated maps? This would be convenient for further R processing.
>
You could consider replacing the for-loop by calls to lapply/mapply. This way the objects
representing one day are held as elements of a single list.

Try the following (with x representing your initial dataset as a data.frame and foo.* your own
functions doing the interpolation/plotting, thus more or less the code from your loop put in a few
functions):

idw.list <- lapply(x, foo.idw) # gives a list with each element representing the map of one day
ok.list <- lapply(x, foo.ok)
plots <- mapply(foo.plotting, idw.list, ok.list) # gives one plot per day, with foo.plotting using
spplot as Edzer suggested for example

For writing your own functions consider the respective chapter in the "Introduction to R" you find
in the build-in help (use help.start() for example).

regards,
Tom



More information about the R-sig-Geo mailing list