grouped_weighted_mean {flashlight} | R Documentation |
Fast Grouped Weighted Mean
Description
Fast version of grouped_stats(..., counts = FALSE)
.
Works if there is at most one "by" variable.
Usage
grouped_weighted_mean(
data,
x,
w = NULL,
by = NULL,
na.rm = TRUE,
value_name = x
)
Arguments
data |
A |
x |
Variable name in |
w |
Optional name of the column in |
by |
An optional vector of column names in |
na.rm |
Should missing values in |
value_name |
Name of the resulting column with means. |
Value
A data.frame
with grouped weighted means.
Examples
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")
[Package flashlight version 0.9.0 Index]