I am trying to obtain some summary statistics in R using the dplyr package. Although weighted means are easy to get, I struggle with weighted SD. Typically I use the radiant.data package, but for this analysis I want to get the standard deviation by two grouping variables (time and gender).
Below is the code I am using for obtaining weighted means:
group_by(time, gender) %>%
summarise(Mean=mean(x, na.rm=T, wt=weights))
Typically, I use the below code for weighted SD:
weighted.sd(df$x, df$weights, na.rm = T)
However, I cannot get that function to work within dplyr. Any ideas?
Additionally, is there any way to combine functions so that I can see two columns, one for weighted mean and one for weighted SD?
Thanks!