[R] raster time series statistics

David Winsemius dwinsemius at comcast.net
Tue Mar 6 09:10:53 CET 2018


> On Mar 5, 2018, at 9:07 PM, <Alexander.Herr at csiro.au> <Alexander.Herr at csiro.au> wrote:
> 
> It works if you use as.Date. But this defeates the purpose for the yearmon notion...
> 
> require(raster)
> require(rts)
> require(stringr)
> r <- raster(ncol=100, nrow=100)
> values(r) <- runif(ncell(r))
> stack(r)->s
> r->rs
> for(i in 1:23){
> rs[]<-r[]*i
>  addLayer(s,rs)->s
> print(nlayers(s))
> }
> dt<-list(ID=seq(1:24),month=rep(formatC(1:12,flag=0,width=2),2), year=sort(rep(2016:2017,12)))
> timelst<-paste0(unlist(dt['year']),'-',unlist(dt['month']),"-01")
> strptime(timelst,format="%Y-%m-%d")->t1
> 
> 
> rts(s,time=as.yearmon(t1))->rsts
> subset(rsts,'2017')->r2017
> class(r2017 at time)
> class(rsts at time)
> apply.monthly(rsts,mean) # this creates error
> 
> rts(s,time=as.Date(t1))->rsts1
> apply.monthly(rsts1,mean) # this creates output

So it appears that you have shown that apply.monthly doesn't work with 'yearmon'-classed vectors in the endpoints of a RasterStackTS. It's not documented as doing so after all. So this is really a feature request for the maintainer. You should contact the responsible individual.

maintainer('rts')
[1] "Babak Naimi <naimi.b at gmail.com>"

> 
> 
> -----Original Message-----
> From: Jim Lemon [mailto:drjimlemon at gmail.com] 
> Sent: Tuesday, 6 March 2018 11:40 AM
> To: Herr, Alexander (L&W, Black Mountain) <Alexander.Herr at csiro.au>
> Cc: David Winsemius <dwinsemius at comcast.net>; r-help mailing list <r-help at r-project.org>
> Subject: Re: [R] raster time series statistics
> 

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list