Hi Everyone,
I'm currently trying to calculate a weighted average using dplyr on a time series every 12 hours. I've writte code that seems to work properly for a normal arithmetic mean. Seen here:
AverageMet12<-Hour12Met%>%
filter(LWC >= 0.05)%>%
collapse_by("12 hourly", Date = FullDate, start_date = "2014-05-31 17:59:00")%>%
group_by(FullDate)%>%
summarise_if(is.numeric, mean, na.rm = TRUE)
However, I want to calculated a weighted average, so I would assume that this code would work but it doesn't
AverageMet12<-Hour12Met%>%
filter(LWC >= 0.05)%>%
collapse_by("12 hourly", Date = FullDate, start_date = "2014-05-31 17:59:00")%>%
group_by(FullDate)%>%
summarise_if(is.numeric, weighted.mean(w = CLOUD_HR), na.rm = TRUE)
I get there error:
Error in weighted.mean(w = CLOUD_HR) : object 'CLOUD_HR' not found
Is there a better what of doing this?
My variable names include "CLOUD_HR", "LWC", "PSA", and "WDR". I know I have the spelling of my variables correct.