[R-sig-Geo] marktable function

adrian at maths.uwa.edu.au adrian at maths.uwa.edu.au
Fri Feb 1 05:44:42 CET 2008

Here's a function that tabulates, for each point in a multitype point
pattern, the number of other points of each type within an R-neighbourhood
of the current point.


marktable <- function(X,R) {
    verifyclass(X, "ppp")
    npoints <- X$n
    m <- marks(X)
    p <- closepairs(X, R)
    i <- factor(p$i, levels=1:npoints))
    mj <- m[p$j]
    table(point=i, mark=mj)

I've tested it on a pattern of 10,000 points in the unit square with
neighbourhood radius R = 0.1, giving an average of 314 neighbours for each
point (i.e. a total of 3.14 million pairs to be counted). It runs out of
space when the number of pairs to be counted exceeds about 10 million.

This function will be added to the next release of spatstat (1.12-6)

Adrian Baddeley

More information about the R-sig-Geo mailing list