grouped_weighted_mean: Fast Grouped Weighted Mean

View source: R/grouped_weighted_mean.R

grouped_weighted_meanR 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 data.frame.

x

Variable name in data to summarize.

w

Optional name of the column in data with case weights.

by

An optional vector of column names in data used to group the results.

na.rm

Should missing values in x be removed?

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")

flashlight documentation built on May 31, 2023, 6:19 p.m.