diff --git a/functions.Rmd b/functions.Rmd index 65bf7ed..f65be0e 100644 --- a/functions.Rmd +++ b/functions.Rmd @@ -528,7 +528,7 @@ As you start to write more functions, you'll eventually get to the point where y ```{r} wt_mean <- function(x, w) { - sum(x * w) / sum(x) + sum(x * w) / sum(w) } wt_var <- function(x, w) { mu <- wt_mean(x, w) @@ -554,7 +554,7 @@ wt_mean <- function(x, w) { if (length(x) != length(w)) { stop("`x` and `w` must be the same length", call. = FALSE) } - sum(w * x) / sum(x) + sum(w * x) / sum(w) } ``` @@ -577,7 +577,7 @@ wt_mean <- function(x, w, na.rm = FALSE) { x <- x[!miss] w <- w[!miss] } - sum(w * x) / sum(x) + sum(w * x) / sum(w) } ``` @@ -593,7 +593,7 @@ wt_mean <- function(x, w, na.rm = FALSE) { x <- x[!miss] w <- w[!miss] } - sum(w * x) / sum(x) + sum(w * x) / sum(w) } wt_mean(1:6, 6:1, na.rm = "foo") ```