Skip to contents

This function computes the *weighted sum* for each column in an input matrix. See the **Details** section below for further information.

Usage

colWeightedSums(x, w, rows = NULL, na.rm = TRUE, ...)

Arguments

x

a numerical matrix features-by-samples

w

numerical vector of weights. Its length must match the number of rows in x

rows

(optional) numerical vector giving the rows in x or character vector matching the row names in x to operate over. If missing or rows = NULL, all the rows in x are considered for the computation of the measures

na.rm

logical, whether to remove NA values from x before computation

...

currently not used

Value

A numerical vector containing the computed score for each column in x.

Details

This function applies colSums2 to each column of the matrix resulting from w * x.

Author

Alessandro Barberis

Examples

x = matrix(data = c(1,3,1,4), ncol = 2)
w = c(5, 1)
colWeightedSums(x = x, w = w)
#> [1] 8 9