addXPtr {rrp} | R Documentation |
Adds constant to the elements of a XPtr
object vector-wise. The idea is
that a symmetrix matrix M
can be represented as a triangular object
d
. With this function you set M[x,x] = M[x,x] + k
but instead of
working on M
this function works on its XPtr
representation
d
.
addXPtr(d, x, k)
d |
a XPtr object, lower diagonal, representing a symmetric
matrix |
x |
a list of vectors of indices |
k |
a vector of constants to add, arguments are eventually recycled silently |
returns the modified XPtr
object
Stefano M. Iacus
M <- matrix(0,5,5) d <- newXPtr(5,0) x <- list(1:3, 4:5) addXPtr(d,x,c(-1,+1)) # which is the equivalent of (apart for the diagonal elements) M[1:3,1:3] <- M[1:3,1:3] - 1 M[4:5,4:5] <- M[4:5,4:5] + 1 # Indeed, we have (XPtrToDist(d)) as.dist(M)