There are some good tidbits in this discussion, but the answers are incomplete. Remember, calculations require precision and details to be helpful.
Consider the following:
u v Speed direction
0.26 -2.99 3 355
-0.87 -9.96 10 5
-3.62 -13.52 14 15
Obviously, the average wind direction is 5 deg. But basic averaging by (355+5+15)/3 gives an answer of 125 deg, which is incorrect. The problem is that compass angles are circular and have a discontinuity for north winds where the angle in the northwest quadrant is from 270-360 deg and in the northeast quadrant is 0-90 deg.
One solution is a variant of the mean of circular quantities technique. The math technique is described at
https://en.wikipedia.org/wiki/Mean_of_circular_quantities with meteorological details in Yamartino (1984). One does vector addition for each component, then performs an arctangent of the summed components ratio to get the average direction. This method has the following equations:
Step 1: Sum the sines and cosines of wind direction ϕ:
ssum=sum all sinϕ
scos=sum all cosϕ
Step 2: Compute the average
ϕ_avg=(180/pi)* atan2(ssum,scos); if ϕ_avg<0,then ϕ_avg=ϕ_avg+360
For example, in the above example in radians mode:
ssum=sin{355*(pi/180)}+sin{5*(pi/180)}+sin{15*(pi/180)}=0.26
csum=cos{355*(pi/180)}+cos{5*(pi/180)}+cos{15*(pi/180)}=2.96
Then the result for the average wind direction is:
ϕ_avg=180/pi*atan2(0.26,2.96)=5 deg