[R] Classification of wind events

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Tue May 19 03:02:35 CEST 2020


Sorry, I should know better:

rollmean<-function(x,width=2) {
 lenx<-length(x)
 result<-rep(NA,lenx)
 for(i in 1:lenx) {
  chunk<-i:(i+width-1)
  if(i<width) chunk<-c(rep(1,width-i),1:i)
  if(i>(lenx-width)) chunk<-c(i:lenx,rep(lenx,i-(width-1)))
  result[i]<-mean(x[chunk])
 }
 return(result)
}

I forgot to replace this with:

library(zoo)
rollmean...

Jim

On Tue, May 19, 2020 at 1:26 AM Jeff Newmiller <jdnewmil using dcn.davis.ca.us> wrote:
>
> ? source("../rollmean.R") ?
>
> On May 18, 2020 4:11:52 AM PDT, Jim Lemon <drjimlemon using gmail.com> wrote:
> >Hi Stefano,
> >If I understand your request, this may also help, Uses the same data
> >transformations as my previous email.
> >
> >png("SS_foehn.png")
> >plot(mydf$data_POSIX,
> > ifelse(mydf$main_dir %in% c("WSW","SW"),mydf$max_speed,NA),
> > type="b",main="Wind speed (WSW or SW) by time",
> > xlab="Time of day",ylab="Wind speed km/h",
> > col=rainbow(16)[as.numeric(mydf$main_dir)])
> >abline(h=8,col="orange",lwd=2)
> >source("../rollmean.R")
> >rmws<-rollmean(mydf$max_speed,4)
> >lines(mydf$data_POSIX,rmws,col="orange",lwd=2)
> >legend("topleft","Rolling mean of 4 for wind speed",
> > lty=1,lwd=2,col="orange")
> >dev.off()
> >
> >Jim
>
> --
> Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list