# NOT RUN {
## GPA from Siegel 1994
wt <- c(5, 5, 4, 1)/15
x <- c(3.7,3.3,3.5,2.8)
var(x)
weighted_variance(x = x)
weighted_variance(x = x, weights = wt)
weighted_variance(x = x, weights = wt, weights_counts = TRUE)
weights <- c(5, 5, 4, 1)
weighted_variance(x = x, weights = weights)
weighted_variance(x = x, weights = weights, weights_counts = FALSE)
weighted_variance(x = data.frame(x, wt), var = "x",
weight = "wt")
# apply by groups:
fritools::tapply(object = mtcars,
index = list(mtcars[["cyl"]], mtcars[["vs"]]),
func = weighted_variance, var = "mpg", w = "wt")
# }
Run the code above in your browser using DataLab