| smtools {GeneTS} | R Documentation |
sm2vec takes a symmetric matrix and puts
the lower triagonal entries into a vector (cf. lower.tri).
sm.indexes gives the corresponding x-y-indexes for each entry
in the vector produced by sm2vec.
vec2sm reverses the operation by sm2vec and turns the
vector back in a symmetric matrix. If diag=FALSE the
diagonal of the resulting matrix will consist of NAs. If order
is supplied then the input vector vec will first be rearranged accordingly.
sm2vec(m, diag = FALSE) sm.indexes(m, diag = FALSE) vec2sm(vec, diag = FALSE, order = NULL)
m |
symmetric matrix |
diag |
logical. Should the diagonal be included? |
vec |
vector of unique elements from a symmetric matrix |
order |
order of the entries in vec |
A vector (sm2vec), a two-column matrix with indexes (sm.indexes),
or a symmetric matrix (vec2sm).
Korbinian Strimmer (http://www.statistik.lmu.de/~strimmer/).
# load corpcor library
library("corpcor")
# covariance matrix
m.cov <- rbind(
c(3,1,1,0),
c(1,3,0,1),
c(1,0,2,0),
c(0,1,0,2)
)
m.cov
# convert into vector (including diagonals
v <- sm2vec(m.cov, diag=TRUE)
v.idx <- sm.indexes(m.cov, diag=TRUE)
v
v.idx
# put back to symmetric matrix
vec2sm(v, diag=TRUE)
# vector not in the original order
sv <- sort(v)
sv
ov <- order(v)
ov
vec2sm(sv, diag=TRUE, order=ov)