Splits the data into subsets (according to the levels of a factor) and computes the weighted variance for each

agg.wtd.var(x, by, weights = NULL, na.rm = FALSE)

Arguments

x

numeric vector or data frame of numeric vectors

by

factor used to split the data

weights

numeric vector of weights. If NULL (default), uniform weights (i.e. all equal to 1) are used.

na.rm

logical, indicating whether NA values should be silently removed before the computation proceeds. Default is FALSE.

Value

a data frame

Author

Nicolas Robette

See also

Examples

data(Movies)
agg.wtd.var(Movies[,c("Critics", "BoxOffice")], by = Movies$Country)
#>          Critics    BoxOffice
#> Europe 0.5371399 2.682983e+12
#> France 0.7173937 5.773407e+11
#> Other  0.6464152 1.859813e+12
#> USA    0.7398166 1.867448e+12