Learn R Programming

surveillance (version 1.5-4)

multiplicity: Count Number of Instances of Points

Description

The multiplicity S3-generic function defined in surveillance is intended as a simple auxiliary function, which counts the number of instances of each row in a numeric matrix (or data.frame), or of each point in a Spatial object. Indeed, this just computes the distance matrix of the rows (points), and then counts the number of zeroes in each row.

Usage

multiplicity(x, ...)

## S3 method for class 'default': multiplicity(x, ...) ## S3 method for class 'Spatial': multiplicity(x, ...)

Arguments

x
an object, for which a multiplicity method is defined, e.g. a numeric matrix (or anything coercible to it by as.matrix) or an object of class "SpatialPoints".
...
currently unused.

Value

  • an integer vector containing the number of instances at each point of the object.

See Also

Examples of the hagelloch data for a specific use of this function.

Examples

Run this code
foo <- matrix(c(1,2,3,
                2,3,4,
                1,2,3,
                4,5,6), byrow=TRUE, ncol=3)
multiplicity(foo)

# the following function determines the multiplicity of rows of a
# numeric matrix and returns unique rows with appended multiplicity
countunique <- function (matrix) {
    count <- multiplicity(matrix)
    unique(cbind(matrix, count))
}
countunique(foo)

Run the code above in your browser using DataLab