> I think the point I wanted to make was, if a function aggregates, can it
be made into a method instance that has the name "aggregate".

I think it is a good idea, and I think it can be done, by letting the code
fork based on the arguments that are supplied to aggregate. It could be
interesting to allow space-layer (time) aggregation in one step.

> Why, in zApply, did you choose the signature (x, by, fun=mean, ...)

The raster package used 'fun' throughout, rather than 'FUN'. Capitalization
of arguments is odd in R, except for FUN, which is consistently used, and
it would have been better to follow that pattern. I might change that.

The 'experimental' in zApply refers to the fact that it is new function
reflecting a prolonged process of finding the best way to deal with
computation across layers, in part because the layers may not represent
time. By the way, stackApply is also used in this context.

Robert

On Mon, Oct 31, 2011 at 6:55 AM, Edzer Pebesma <
edzer.pebesma@uni-muenster.de> wrote:

> Oscar, good to see that that works (although I couldn't work out the logic
> behind the ordering of months in plot(sMean))
>
> I think the point I wanted to make was, if a function aggregates, can it
> be made into a method instance that has the name "aggregate".
>
> How does a user find out s/he needs zApply? Or Which or which?
>
> Why, in zApply, did you choose the signature (x, by, fun=mean, ...) where
> aggregate has (x, by, FUN, ...) ?
>
> I believe that adding functions adds to complexity, where adding to
> methods reduces it.
>
>
> On 10/31/2011 12:32 PM, Oscar Perpiñan Lamigueiro wrote:
>
>> Hello,
>>
>> I think the zApply method in raster could be useful here. For example:
>>
>> library(sp)
>> library(raster)
>>
>> ## 30 rows, 84 cols, 399 layers of data
>> url<- "ftp://ftp.wiley.com/public/**sci_tech_med/spatio_temporal_**data/<ftp://ftp.wiley.com/public/sci_tech_med/spatio_temporal_data/>
>> "
>> sst.dat = read.table(paste(url, "SST011970_032003.dat", sep=''), header
>>        = FALSE)
>> sst.ll = read.table(paste(url, "SSTlonlat.dat", sep=''),
>>        header = FALSE)
>>
>> sp<- SpatialPointsDataFrame(sst.ll, sst.dat)
>> gridded(sp)<- TRUE
>> proj4string(sp) = "+proj=longlat +datum=WGS84"
>> s<- brick(sp)
>>
>> idx<- seq(as.Date('1970-01-01'), as.Date('2003-03-01'), by='month')
>> s<- setZ(s, idx)
>> layerNames(s)<- as.character(idx)
>>
>> sMean<- zApply(s,  by = months)
>>
>> Best,
>>
>> Oscar.
>>
>>
>>
>> -------------------
>> Oscar Perpiñán Lamigueiro
>> Dpto. Ingeniería Eléctrica
>> EUITI-UPM
>>
>> http://procomun.wordpress.com
>>
>>  Dear Carsten, Tom, Robert and Edzer,
>>> thank you very much for your answers! And yes Robert, you are right, I
>>> like to calculate the mean of raster cells across the layers. I just
>>> tried the EtRR.sum<- calc(EtRR, mean)  on the layer stack.
>>> Unfortunately the computation of only one month is taking now longer
>>> than the computation of all 12 months using my old script. I will now
>>> have a look on Edzers proposal.
>>>
>>> Again, thank you all!
>>>
>>> Best,
>>>
>>> Swen
>>>
>>>
>>> Am 31.10.2011 09:58, schrieb Edzer Pebesma:
>>>
>>>> So, raster::aggregate does spatial aggregation, and calc does
>>>> temporal aggregation when the stack reflect time. Do you see
>>>> possibilities to extend the behaviour of raster::aggregate to
>>>> generalize stats::aggregate, and e.g. in the temporal domain to
>>>> extend/reuse zoo::aggregate? Besides a grouping predicate ("by"),
>>>> zoo::aggregate allows a grouping function that works on time, giving
>>>> you e.g. aggregations to monthly, quarterly and yearly values
>>>> without effort.
>>>>
>>>> I tried this approach for the classes in package spacetime, some of
>>>> which generalize the raster time-stack but lack its powerful disk
>>>> caching. For spatio-temporal objects this was documented here:
>>>> http://cran.r-project.org/web/**packages/spacetime/vignettes/**sto.pdf<http://cran.r-project.org/web/packages/spacetime/vignettes/sto.pdf>
>>>> and for spatial (sp) objects here:
>>>> http://cran.r-project.org/web/**packages/sp/vignettes/over.pdf<http://cran.r-project.org/web/packages/sp/vignettes/over.pdf>
>>>>
>>>> Any comments welcome. Best regards,
>>>> --
>>>> Edzer
>>>>
>>>
> --
> Edzer Pebesma
> Institute for Geoinformatics (ifgi), University of Münster
> Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
> 8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
> http://www.52north.org/**geostatistics<http://www.52north.org/geostatistics>
> e.pebesma@wwu.de
>

	[[alternative HTML version deleted]]

