Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rowSums.dist

Row Sums/Means of Sparse Symmetric Matrices


Description

Compute the row (column) sums or means for a sparse symmetric (distance) matrix.

Usage

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)

Arguments

x

an object of class dist.

na.rm

logical, should missing values (including NaN) be omitted from the summation?

diag

logical, should the diagonal elements be included in the computation?

Details

These functions are more efficient than expanding an object of class dist to matrix and using rowSums or rowMeans.

colSums and colMeans are provided for convenience. However, note that due to symmetry the result is always the same as for rowSums or rowMeans.

Value

A numeric vector of row sums.

Author(s)

Christian Buchta

See Also

as.matrix, as.dist, and rowSums.

Examples

## 
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[3] <- NA
rowSums.dist(d, na.rm = TRUE)
rowMeans.dist(d, na.rm = TRUE)

proxy

Distance and Similarity Measures

v0.4-25
GPL-2
Authors
David Meyer [aut, cre], Christian Buchta [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.