View source: R/grouped_stats.R
grouped_stats | R Documentation |
Calculates weighted means, quartiles, or variances (and counts) of a variable grouped by optional columns. By default, counts are not weighted, even if there is a weighting variable.
grouped_stats(
data,
x,
w = NULL,
by = NULL,
stats = c("mean", "quartiles", "variance"),
counts = TRUE,
counts_weighted = FALSE,
counts_name = "counts",
value_name = x,
q1_name = "q1",
q3_name = "q3",
...
)
data |
A |
x |
Variable name in |
w |
Optional name of the column in |
by |
An optional vector of column names in |
stats |
Statistic to calculate: "mean", "quartiles", or "variance". |
counts |
Should group counts be added? |
counts_weighted |
Should counts be weighted by the case weights?
If |
counts_name |
Name of column in the resulting |
value_name |
Name of the resulting column with mean, median, or variance. |
q1_name |
Name of the resulting column with first quartile values.
Only relevant if |
q3_name |
Name of the resulting column with third quartile values.
Only relevant if |
... |
Additional arguments passed to corresponding |
A data.frame
with columns by
, x
, and optionally counts_name
.
grouped_stats(iris, "Sepal.Width")
grouped_stats(iris, "Sepal.Width", stats = "quartiles")
grouped_stats(iris, "Sepal.Width", stats = "variance")
grouped_stats(iris, "Sepal.Width", w = "Petal.Width", counts_weighted = TRUE)
grouped_stats(iris, "Sepal.Width", by = "Species")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.