weighted_sum: Weighted sum with logical index

View source: R/math.R

weighted_sumR Documentation

Weighted sum with logical index

Description

Computes the weighted sum of x using weights w, where idx is TRUE.

Usage

weighted_sum(x, w, idx)

Arguments

x

Numeric vector of values.

w

Numeric vector of weights, same length as x.

idx

Logical vector indicating which elements to include.

Value

A single numeric value. Returns 0 if no TRUE values in idx.

Examples

idx_active <- c(TRUE, TRUE, FALSE, FALSE, FALSE, TRUE)
AGSA <- c(0.1, 0.2, 0.03, 0.04, 0.05, 0.6)
Duration <- c(100, 90, 80, 70, 60, 50)
ActiveVolume <- weighted_sum(AGSA, Duration, idx_active)

GENEAcore documentation built on Oct. 22, 2026, 5:09 p.m.