linearCombination: Linear Combination of a Matrix

View source: R/matrix.R

linearCombinationR Documentation

Linear Combination of a Matrix

Description

Calculate the linear combination of a matrix

Usage

linearCombination(x, coeffs, version = 1)

Arguments

x

numeric matrix

coeffs

numeric vector of coefficients

version

1 or 2 (default: 1). Allows for two different versions of calculation both of which should return the same!

Examples

(x <- randomMatrix(c(4, 2)))
(coeffs <- rnorm(ncol(x)))
  
# Calculate the linear combination manually
LC1 <- x[, 1] * coeffs[1] + x[, 2] * coeffs[2]

# Caluclate with linearCombination()
LC2 <- linearCombination(x, coeffs)

# The result shoulc be the same!
all.equal(LC1, LC2) # TRUE


KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.