Notes on Linear Algebra Part 3
Want to share your content on Rbloggers? click here if you have a blog, or here if you don't.
This post is a survey of the linear algebrarelated functions from base R
. Some of these I’ve disccused in other posts and some I may discuss in the future, but this post is primarily an inventory: these are the key tools we have available. “Notes” in the table are taken from the help files.
Matrices, including row and column vectors, will be shown in bold e.g. or while scalars and variables will be shown in script, e.g. . R
code will appear like x < y
.
In the table, or is an upper/right triangular matrix. is a lower/left triangular matrix (triangular matrices are square). is a generic matrix of dimensions . is a square matrix of dimensions .
Function  Uses  Notes  

operators  
* 
scalar multiplication  
%*% 
matrix multiplication  two vectors the dot product; vector + matrix cross product (vector will be promoted as needed)^{1}  
basic functions  
t() 
transpose  interchange rows and columns  
crossprod() 
matrix multiplication  faster version of t(A) %*% A 

tcrossprod() 
matrix multiplication  faster version of A %*% t(A) 

outer() 
outer product & more  see discussion below  
det() 
computes determinant  uses the LU decomposition; determinant is a volume  
isSymmetric() 
name says it all  
Conj() 
computes complex conjugate  
decompositions  
backsolve() 
solves  
forwardsolve() 
solves  
solve() 
solves and  e.g. linear systems; if given only one matrix returns the inverse  
qr() 
solves  is an orthogonal matrix; can be used to solve ; see ?qr for several qr.* extractor functions 

chol() 
solves  Only applies to positive semidefinite matrices (where ); related to LU decomposition  
chol2inv() 
computes from the results of chol(M) 

svd() 
singular value decomposition  input ; can compute PCA; details  
eigen() 
eigen decomposition  requires ; can compute PCA; details 
One thing to notice is that there is no LU decomposition in base R
. It is apparently used “under the hood” in solve()
and there are versions available in contributed packages.^{2}
Footnotes
For details see the discussion in Part 1.↩︎
Discussed in this Stackoverflow question, which also has an implementation.↩︎
In fact, for the default
outer()
,FUN = "*"
,outer()
actually callstcrossprod()
.↩︎
Reuse
Citation
@online{hanson2022, author = {Bryan Hanson}, editor = {}, title = {Notes on {Linear} {Algebra} {Part} 3}, date = {20220910}, url = {http://chemospec.org/LinearAlgNotesPt3.html}, langid = {en} }
Rbloggers.com offers daily email updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/datascience job.
Want to share your content on Rbloggers? click here if you have a blog, or here if you don't.