setDist {rrp}R Documentation

Sets the elements of a dist object to a constant vector-wise

Description

Sets the elements of a dist object to a constant 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] = k but instead of working on M this function works on its dist representation d.

Usage

setDist(d, x, k)

Arguments

d a dist object, upper diagonal, representing a symmetric matrix
x a list of vectors of indices
k a vector of constants to add, arguments are eventually recycled silently

Value

returns the modified dist object

Author(s)

S. M. Iacus

See Also

dist

Examples

M <- matrix(0,5,5)
d <- as.dist(M)
x <- list(1:3,4:5)

setDist(d,x,c(1,2))
# which is the equivalent of (apart for the diagonal elements)
M[1:3,1:3] <- 1
M[4:5,4:5] <- 2

# Indeed, we have
d
as.dist(M)

[Package rrp version 2.9 Index]