Skip to contents

This function computes the sum of the elements of a vector (x) multiplied by the elements of another vector (w).

Usage

weightedSum(x, w, i = NULL, na.rm = T)

Arguments

x

(named) numerical vector

w

numerical vector of weights the same length as x

i

(optional) numerical vector giving the position in x or character vector matching the names in x. If missing or i = NULL, the entire x is considered for the computation of the score

na.rm

logical, whether to remove NA values from x before computation

Value

A numerical value representing the computed measure. A default NA value is returned if the score can't be computed.

Author

Alessandro Barberis

Examples

x = c(1,1,2,3,3,3,NA)
w = c(1,1,8,1,1,1,1)
weightedSum(x = x, w = w, na.rm = TRUE)
#> [1] 27