6

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?

Cath
  • 23,906
  • 5
  • 52
  • 86
KS Lee
  • 81
  • 1
  • 6

2 Answers2

10

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 wdiryou 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
Community
  • 1
  • 1
germcd
  • 954
  • 1
  • 12
  • 24
  • thanks for your comment. I have a additional question. That's a hourly data and I want to calculate daily, 6hour seq etc... various time interval mean. How can I do this? – KS Lee Dec 01 '15 at 14:13
  • 1
    @LeeKi-Seop [this](http://stackoverflow.com/questions/24745402/r-rolling-window-function-with-adjustable-window-and-step-size-for-irregularly) might help or you may get help with that problem by asking another question with reproducible data. – germcd Dec 01 '15 at 14:36
  • This is a great solution, but note that `mean(circular(data))` will calculate the answer as rotation around the circle from zero, in positive up to 180 and negative down to -180. You'll want to add 360 to *just* the negative values to get answers from 0 to 360. – Nat Nov 05 '20 at 19:33
4

You can't simply average the wind direction, you need the speed for each direction and with the speed you can evaluate the average considering the vector form. Another way is to convert wind speed and direction into u and v components, than you can average u and v separately and then evaluating speed and direction. Wind spd = sqrt(u^2+v^2); wind dir = atan2(u,v)*(180/pi)+180