0

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 esectorevery 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

It would be great if i can choose the number of sectors and automatically generate the list of mean wind speeds and mean direction. Thanks.

SamAct
  • 529
  • 4
  • 23

2 Answers2

1

Actually I'm working with the same data. First I do a wind rose like this: enter image description here

And then, depending the direction, I put the data:

max(Windspeed[direc >=11.25 & direc <= 33.75])
min(Windspeed[direc >=11.25 & direc <= 33.75])
mean(Windspeed[direc >=11.25 & direc <= 33.75])

I put he direccion in degrees. If you don't search that, I will be here waiting for help you.

David Arenburg
  • 91,361
  • 17
  • 137
  • 196
0

Okay working on the idea by @monse-aleman and similar question by her, here. I was able to automate the program to give the required answer. The function listed is as:

 in_interval <- function(x, interval){
stopifnot(length(interval) == 2L)
interval[1] < x & x < interval[2]
}

Using the above code over the data-set we get.

##Consider a dummy Wind Speed and Direction Data.
ws<-c(seq(1,25,by=0.5))
wd<-c(seq(0,360,by=7.346939))
## Determine the sector starting and end points.    
a<-rbind(0.0  ,22.5  ,45.0  ,67.5  ,90.0 ,112.5 ,135.0 ,157.5 ,180.0 ,202.5 ,225.0 ,247.5 ,270.0 ,292.5 ,315.0,337.5)
b<-rbind(22.5  ,45.0  ,67.5  ,90.0 ,112.5 ,135.0 ,157.5 ,180.0 ,202.5 ,225.0 ,247.5 ,270.0 ,292.5 ,315.0,337.5,360)
sectors<-cbind(a,b)
sectors
## See the table of the sector.

      [,1]  [,2]
 [1,]   0.0  22.5
 [2,]  22.5  45.0
 [3,]  45.0  67.5
 [4,]  67.5  90.0
 [5,]  90.0 112.5
 [6,] 112.5 135.0
 [7,] 135.0 157.5
 [8,] 157.5 180.0
 [9,] 180.0 202.5
[10,] 202.5 225.0
[11,] 225.0 247.5
[12,] 247.5 270.0
[13,] 270.0 292.5
[14,] 292.5 315.0
[15,] 315.0 337.5
[16,] 337.5 360.0

for(o in 1:16){

    mean[o]<-mean(ws[in_interval(wd, c(sectors[o,1], sectors[o,2]))])

  }
mean
[1]  2.0  3.5  5.0  6.5  8.0  9.5 11.0 12.5 14.0 15.5 17.0 18.5 20.0 21.5 23.0 24.5

This is the result. Works quite well.

SamAct
  • 529
  • 4
  • 23