I am trying to get mean wind speeds of a data-set based on its mean direction within a sector. It is fairly simple and the below program does the trick. I, however, am unable to automate it, meaning I have to manually input the values of fsector
and esector
every time. Also, the output is not where I would like. Please tell me a better way or help me on improving this one.
##Dummy Wind Speed and Directional Data.
ws<-c(seq(1,25,by=0.5))
wd<-C(seq(0,360,by=7.346939))
fsector<-22.5 ##Starting point
esector<-45 ##End point
wind <- as.data.frame(cbind(ws,wd))
wind$test<- ifelse(wind$wd > fsector & wind$wd < esector,'mean','greater')
mean<-rbind(aggregate(wind$wd,by=list(wind$test),mean))
meanws<-rbind(aggregate(wind$ws,by=list(wind$test),mean))
mean<-cbind(meanws[2,2],mean[2,2])
mean