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

Soenario, Ivan (KNMI) Ivan.Soenario at knmi.nl
Fri Aug 21 17:22:46 CEST 2009


Thanks everyone for the help!

The solutions as proposed by Pebesma & Gottfried got me a little
further. I've replaced the for-loop with:

jan2000_idw <- lapply(1:3, function(i)
idw(as.formula(paste(names(Pd200001[i+2]), "~1", sep="")), Pd200001,
nl.grd))

(Just for first three days, to see if it was working)

And I get an image:
image(jan2000_idw[[1]])

But I don't fully understand Pebesma solution to printing with spplot,
nor Gottfrieds suggestion of mapply.

What I'd like to obtain is 31 images with idw interpolation and 31
images with kriging images, so I can compare them.

plots <- mapply(foo.plotting, jan2000_idw, jan2000_kri)

What should foo.plotting look like?

foo.plotting <- function() {
spplot()
dev.copy(jpg, etc, etc)
dev.off()
}

And what does plots look like? Is it a list with jpg's?

Thanks again

Ivan Soenario



-----Oorspronkelijk bericht-----
Van: r-sig-geo-bounces at stat.math.ethz.ch
[mailto:r-sig-geo-bounces at stat.math.ethz.ch] Namens Tom Gottfried
Verzonden: woensdag 19 augustus 2009 14:54
Aan: r-sig-geo at stat.math.ethz.ch
Onderwerp: Re: [R-sig-Geo] daily precipitation idw & kriging andbeginner
questions

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

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list