File: rowSums.dist.Rd

package info (click to toggle)
r-cran-proxy 0.4-27-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 372 kB
  • sloc: ansic: 1,247; sh: 12; makefile: 5
file content (53 lines) | stat: -rwxr-xr-x 1,447 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
\name{rowSums.dist}
\alias{rowSums.dist}
\alias{colSums.dist}
\alias{rowMeans.dist}
\alias{colMeans.dist}
\title{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{
  \item{x}{an object of class \code{dist}.}
  \item{na.rm}{logical, should missing values (including \code{NaN}) be
    omitted from the summation?}
  \item{diag}{logical, should the diagonal elements be included
    in the computation?}
}
\details{
  These functions are more efficient than expanding an object of
  class \code{dist} to matrix and using \code{rowSums} or \code{rowMeans}.

  \code{colSums} and \code{colMeans} are provided for convenience.
  However, note that due to symmetry the result is always the
  same as for \code{rowSums} or \code{rowMeans}.
}
\value{
  A numeric vector of row sums.
}
\author{Christian Buchta}
\seealso{\code{as.matrix}, \code{as.dist}, and \code{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)
}
\keyword{cluster}