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@time)
class(rsts@time)
apply.monthly(rsts,mean) # this creates error

rts(s,time=as.Date(t1))->rsts1
apply.monthly(rsts1,mean) # this creates output


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

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to