I have this data set https://gist.github.com/natemiller/42eaf45747f31a6ccf9a
I'm trying to apply a rolling regression using the rollapply
in the zoo package, following the examples in the rollapply
help and keep getting what I imagine is a simple error, but one I haven't been able to work around.
If I load the above data as "dat" then I do this..
dat$Date<-as.POSIXct(dat$Date, format="%m/%d/%y %H:%M")
library(zoo)
roll<-rollapply(dat, width = 6, FUN = function(d) coef(lm(Temp~Date, data=d)), align="right")
and I get the error
Error in eval(predvars, data, env) : invalid 'envir' argument
dat
should be an appropriate input to lm
, this lm
works outside of rollapply
, so the error arises in the rollapply
itself. I assume its simple, but I'd appreciate help.
Thanks