I have a data set which consist of wind direction vector, as follows:
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)
Scalar values are in degrees.
How can I calculate mean wind direction?
This can be done using the circular
package.
To get the mean of 45
and 315
you can use:
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
The reason it isn't exactly 0
is because of floating point precision in R
.
To get the mean of wdir
you can use:
mean(circular(wdir, units = "degrees"))
#Circular Data:
#Type = angles
#Units = degrees
#Template = none
#Modulo = asis
#Zero = 0
#Rotation = counter
#[1] 41.05411
Another example:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With