Compute the row (column) sums or means for a sparse symmetric (distance) matrix.
rowSums.dist(x, na.rm = FALSE) rowMeans.dist(x, na.rm = FALSE, diag = TRUE) colSums.dist(x, na.rm = FALSE) colMeans.dist(x, na.rm = FALSE, diag = TRUE)
an object of class
logical, should missing values (including
logical, should the diagonal elements be included in the computation?
These functions are more efficient than expanding an object of
dist to matrix and using
colMeans are provided for convenience.
However, note that due to symmetry the result is always the
same as for
A numeric vector of row sums.
## x <- matrix(runif(10*2),ncol=2) d <- dist(x) rowSums(as.matrix(d)) rowSums.dist(d) # the same rowMeans(as.matrix(d)) rowMeans.dist(d) # the same rowMeans.dist(d, diag = FALSE) # not the same ## NAs d <- NA rowSums.dist(d, na.rm = TRUE) rowMeans.dist(d, na.rm = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.