svd_byname: Calculate the singular value decomposition of a matrix

View source: R/Unary.R

svd_bynameR Documentation

Calculate the singular value decomposition of a matrix

Description

The singular value decomposition decomposes matrix A into A = U D V^T, where U and V are orthogonal matrices and D is a diagonal matrix. U is the left singular vectors of A. V is the right singular vectors of A.

Usage

svd_byname(a, which = c("d", "u", "v"))

Arguments

a

A matrix to be decomposed.

which

The matrix to be returned. Default is "d". See details.

Details

which determines the part of the singular value decomposition to be returned. "d" (default) gives the D matrix. "u" gives the U matrix. "v" gives the V matrix (not its transpose).

Value

A matrix of the singular value decomposition of a.

Examples

A = matrix(c(4, 0, 
             3, -5), nrow = 2, ncol = 2, byrow = TRUE, 
           dimnames = list(c("r1", "r2"), c("c1", "c2"))) %>% 
  setrowtype("Product") %>% setcoltype("Industry")
A
svd_byname(A) # Gives D matrix, by default
svd_byname(A, which = "d")
svd_byname(A, which = "u")
svd_byname(A, which = "v")

matsbyname documentation built on Oct. 19, 2023, 5:11 p.m.