> library(zoo)
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
> z =c(NA,NA,1,2,3)
> rollapply(z,width=2,max,fill=NA,align="r",na.rm=T)
[1] NA -Inf 1 2 3
Warning message:
In FUN(data[posns], ...) : no non-missing arguments to max; returning -Inf
>
I do understand that the max of an empty set is -Inf. This is mentioned in ?max.
That explains why the rollapply at the second position is -Inf. I think that at the second position, we remove the 2 NA's on position 1 and 2, and we are left with an empty set and hence the max is -Inf.
My query is : Why is the rollapply at the first position NA?
Should it also not be -Inf? Can someone please explain? What is the rationale behind it ?
If there are fewer than 2 points available then it does not run
maxat all but rather outputs thefillvalue which is NA. If-Infwere wanted then specifyfill = -Infor alternately usepartial=TRUEwhich will usemaxeven if there are less than 2 points available.Note that we can avoid the warnings from
maxby additionally passing-Inftomax: