The generic function
multiplicity defined in spatstat.geom is
intended to count the number of duplicates of each element of an object.
spatstat.geom already offers methods for point patterns, matrices and
data frames, and here we add a method for
Spatial objects from
the sp package. It is a wrapper for the default method, which
effectively computes the distance matrix of the points,
and then just counts the number of zeroes in each row.
## S3 method for class 'Spatial' multiplicity(x)
an integer vector containing the number of instances of each point of the object.
1 2 3 4 5 6 7 8 9 10
foo <- SpatialPoints(matrix(c(1,2, 2,3, 1,2, 4,5), 4, 2, byrow=TRUE)) multiplicity(foo) # the following function determines the multiplicities in a matrix # or data frame and returns unique rows with appended multiplicity countunique <- function(x) unique(cbind(x, count=multiplicity(x))) countunique(coordinates(foo))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.