grouped_center {flashlight} | R Documentation |
Grouped, weighted mean centering
Description
Centers a numeric variable within optional groups and optional weights. The order of values is unchanged.
Usage
grouped_center(data, x, w = NULL, by = NULL, ...)
Arguments
data |
A |
x |
Variable name in |
w |
Optional name of the column in |
by |
An optional vector of column names in |
... |
Additional arguments passed to mean calculation (e.g. |
Value
A numeric vector with centered values in column x
.
Examples
ir <- data.frame(iris, w = 1)
mean(grouped_center(ir, "Sepal.Width"))
rowsum(grouped_center(ir, "Sepal.Width", by = "Species"), ir$Species)
mean(grouped_center(ir, "Sepal.Width", w = "w"))
rowsum(grouped_center(ir, "Sepal.Width", by = "Species", w = "w"), ir$Species)
[Package flashlight version 0.9.0 Index]