invert_byname {matsbyname} | R Documentation |
Invert a matrix
Description
This function transposes row and column names as well as row and column types.
Rows and columns of a
are sorted prior to inverting.
Usage
invert_byname(a, method = c("solve", "QR", "SVD"), tol = .Machine$double.eps)
Arguments
a |
The matrix to be inverted. |
method |
One of "solve", "QR", or "SVD". Default is "solve". See details. |
tol |
The tolerance for detecting linear dependencies in the columns of |
Details
The method
argument specifies which method should be used for
calculating the inverse.
"solve" uses base::solve()
and the value of tol
.
"QR" uses base::solve.qr()
and the value of tol
.
"SVD" uses matrixcalc::svd.inverse()
, ignoring the tol
argument.
Both tol
and method
should be a single values and apply to all matrices in a
.
If a
is a singular matrix,
names of zero rows and columns are reported in the error message.
Value
The inversion of a
.
Examples
m <- matrix(c(10,0,0,100), nrow = 2, dimnames = list(paste0("i", 1:2), paste0("c", 1:2))) %>%
setrowtype("Industry") %>% setcoltype("Commodity")
m
invert_byname(m)
matrixproduct_byname(m, invert_byname(m))
matrixproduct_byname(invert_byname(m), m)
invert_byname(list(m,m))
invert_byname(m, method = "QR")
invert_byname(m, method = "SVD")