如何在R中计算风向平均值?

6

我有一个数据集,其中包含风向向量,如下所示:

wdir <- c(296.9, 215.2, 204.8, 110.8, 287.6, 203.4, 253.1, 46.0, 298.8,  62.8, 183.4, 62.3,
          44.3, 97.6, 78.6, 125.6, 116.9, 121.0, 111.2, 335.8, 287.4, 51.7, 232.6, 265.5,
          269.7, 20.5, 17.0, 310.8)

标量值以度为单位。

我如何计算平均风向?


4
mean(wdir) 意味着什么? - thothal
请参考以下内容:这可能会有帮助 - germcd
3
好的,请提供需要翻译的上下文,以便我更好地理解这句话。 - germcd
2个回答

10

这可以使用circular包来完成。

要获得 45315 的平均值,您可以使用:

library(circular)
mean(circular(c(pi/4,7*pi/4)))
#Circular Data: 
#Type = angles 
#Units = radians 
#Template = none 
#Modulo = asis 
#Zero = 0 
#Rotation = counter 
#[1] -1.570092e-16

它不精确地等于0的原因是由于R中的浮点数精度问题

要获取wdir的平均值,您可以使用:

mean(circular(wdir, units = "degrees"))
#Circular Data: 
#Type = angles 
#Units = degrees 
#Template = none 
#Modulo = asis 
#Zero = 0 
#Rotation = counter 
#[1] 41.05411

另一个例子:

mean(circular(c(7*pi/2,pi/4, pi/2, 7*pi/2 )))
#Circular Data: 
#Type = angles 
#Units = radians 
#Template = none 
#Modulo = asis 
#Zero = 0 
#Rotation = counter 
#[1] -0.3926991

谢谢您的评论。我有一个额外的问题。这是按小时计算的数据,我想计算每天、每6小时序列等各种时间间隔的平均值。我该怎么做? - KS Lee
1
@LeeKi-Seop 这个链接或许可以帮到你:https://dev59.com/E4Hba4cB1Zd3GeqPSITO。如果你有可重现的数据,也可以提出另一个问题来获得帮助。 - germcd
这是一个很好的解决方案,但请注意 mean(circular(data)) 将计算答案作为围绕圆圈从零旋转,在正向上到180和负向下到-180。您需要将360添加到负值以获得0到360的答案。 - Nat

4

你不能简单地平均风向,需要每个方向的速度,并通过速度计算矢量形式下的平均值。另一种方法是将风速和方向转换为u和v分量,然后分别对u和v取平均值,再计算速度和方向。风速= sqrt(u^2+v^2);风向= atan2 (u,v)*(180/pi)+180


如果你只有风速和风向,但不知道u和v分量,你会如何处理? - philiporlando

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接