wtd_sum | R Documentation |
This is an improvement on sum
in base-r
.
wtd_sum(x, w = NULL, error = F)
x |
(num vector) A vector of values. |
w |
(num vector) A vector of weights. |
error |
(lgl scalr) Whether to throw an error if there is no data at all or no pairwise complete cases. Default yes. |
It automatically handles missing data. It returns a useful error message if there are no complete cases.
set.seed(1)
X = rnorm(100)
set.seed(1)
W = runif(100)
wtd_sum(X) # not using weights
sum(X) #same as above
wtd_sum(X, W) #different
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.