powered by
Fast version of grouped_stats(..., counts = FALSE). Works if there is at most one "by" variable.
grouped_stats(..., counts = FALSE)
grouped_weighted_mean( data, x, w = NULL, by = NULL, na.rm = TRUE, value_name = x )
A data.frame with grouped weighted means.
data.frame
A data.frame.
Variable name in data to summarize.
data
Optional name of the column in data with case weights.
An optional vector of column names in data used to group the results.
Should missing values in x be removed?
x
Name of the resulting column with means.
n <- 100 data <- data.frame( x = rnorm(n), w = runif(n), group = factor(sample(1:3, n, TRUE)) ) grouped_weighted_mean(data, x = "x", w = "w", by = "group")
Run the code above in your browser using DataLab