【问题标题】:Sector wise mean wind speed and directions in RR中的扇区平均风速和方向
【发布时间】:2017-08-17 21:44:55
【问题描述】:

我试图根据扇区内的平均方向获取数据集的平均风速。这相当简单,下面的程序可以解决问题。但是,我无法使其自动化,这意味着我必须每次手动输入 fsectoresector 的值。此外,输出不是我想要的。请告诉我一个更好的方法或帮助我改进这个。

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

如果我可以选择扇区数并自动生成平均风速和平均风向列表,那就太好了。谢谢。

【问题讨论】:

    标签: r


    【解决方案1】:

    实际上,我正在使用相同的数据。 首先我做一个风玫瑰是这样的:

    然后,根据方向,我放数据:

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

    我把他的方向放在度数上。 如果你不搜索,我会在这里等你。

    【讨论】:

    • 效果很好。我怎么没想到,这么简单。 :D
    • 看到我的回答对您的想法有所改进,这可能会有所帮助。
    【解决方案2】:

    好的,由@monse-aleman 提出这个想法,她here 提出了类似的问题。我能够使程序自动化以给出所需的答案。列出的函数如下:

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

    在我们得到的数据集上使用上面的代码。

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

    这就是结果。效果很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-05
      • 1970-01-01
      • 2023-01-09
      • 2013-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多