Apply a Function to a Point Pattern Broken Down by Factor

Splits a point pattern into sub-patterns, and applies the function to each sub-pattern.

manip, methods, spatial
## S3 method for class 'ppp':
by(data, INDICES=marks(data), FUN, ...)
Point pattern (object of class "ppp").
Grouping variable. Either a factor, a pixel image with factor values, or a tessellation.
Function to be applied to subsets of data.
Additional arguments to FUN.

This is a method for the generic function by for point patterns (class "ppp").

The point pattern data is first divided into subsets according to INDICES. Then the function FUN is applied to each subset. The results of each computation are returned in a list.

The argument INDICES may be

  • a factor, of length equal to the number of points indata. The levels ofINDICESdetermine the destination of each point indata. Theith point ofdatawill be placed in the sub-patternsplit.ppp(data)$lwherel = f[i].
  • a pixel image (object of class"im") with factor values. The pixel value ofINDICESat each point ofdatawill be used as the classifying variable.
  • a tessellation (object of class"tess"). Each point ofdatawill be classified according to the tile of the tessellation into which it falls.
If INDICES is missing, then data must be a multitype point pattern (a marked point pattern whose marks vector is a factor). Then the effect is that the points of each type are separated into different point patterns.


  • A list (also of class "listof") containing the results returned from FUN for each of the subpatterns.

See Also

ppp, split.ppp, cut.ppp, tess, im.

  • by.ppp
# multitype point pattern, broken down by type
  by(amacrine, FUN=density)
  by(amacrine, FUN=function(x) { min(nndist(x)) } )

  # how to pass additional arguments to FUN
  by(amacrine, FUN=clarkevans, correction=c("Donnelly","cdf"))

  # point pattern broken down by tessellation
  tes <- quadrats(swedishpines, 5, 5)
  B <- by(swedishpines, tes, clarkevans, correction="Donnelly")
  unlist(lapply(B, as.numeric))
Documentation reproduced from package spatstat, version 1.16-2, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.