vecvecindex {lazy.mat} | R Documentation |
Returns the index to convert vec(Mat) to vec(t(Mat)) and vice versa.
Description
Returns the index to convert vec(Mat) to vec(t(Mat)) and vice versa.
Usage
vecvecindex(nr, nc = nr)
Arguments
nr |
# of rows |
nc |
# of columns |
Details
Let A be nr x nc.
To create vec(t(A)) from vec(A), use
index=vecvecindex( nr,nc ) # same order as A matrix
vec(t(A)) == vec(A)[index]
To create vec(A) from vec(t(A)), use
index=vecvecindex( nc,nr ) # reverse order
vec(A) == vec(t(A))[index]
Can be used with character matrix.
Commutation matrix can be created by this index.
See lazy.mat::Kmat
function.
Value
vector of index
Examples
A <- demomat(3,2)
vecA <- vec(A); vectA <- vec(t(A))
i1 <- vecvecindex(3,2)
vectA-vecA[i1]
i2 <- vecvecindex(2,3)
vecA-vectA[i2]
# Set the values of the lower triangular matrix from a vector
S=diag(3)
S[upper.tri(S,diag=TRUE)]=c(1,2,3,4,5,6)
printm(S)
S[]=S[index=vecvecindex( 3,3 )]
printm(S)
S=diag(3)
S[upper.tri(S,diag=TRUE)]=c(1,2,3,4,5,6)
S=t(S)
printm(S)
[Package lazy.mat version 0.1.6 ]