Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Averaging wind direction in r

$
0
0

I have hourly u and v wind components, and I’m having trouble to aggregate it to the daily level.

In principle, I thought that I could just take the mean of U and V wind components and find the direction of these means, but the result I get using this algorithm is different from when I use specialized package CircStat. In the code that follows, variable dir_rwind is the direction calculated from the mean U and V components, while dir_CircStat is the mean direction calculated with CircStat.

set.seed(123)

uc <- rnorm(300,0,2)
vc <- rnorm(300,0,2)

df <- data.frame(uc=uc, vc=vc,id=1:10)

df <- cbind(df,as.data.frame(rWind::uv2ds(df$uc,df$vc)))

agg  <- df %>%
  group_by(id)%>%
  summarise(mean_u10 = mean(uc),
            mean_v10 = mean(vc),

            dir_rwind = rWind::uv2ds(mean_u10, mean_v10)[1],

            dir_CircStat = (180/pi)*CircStats::circ.mean(dir*pi/180))
agg

Why do I get different mean wind directions? Should I ever use the first algorithm I tried (taking the mean of each component: like variable dir_rwind)? If yes, when should I use each calculation algorithm?

Thanks a lot


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>