# subset.ppp

##### Extract Subset of Point Pattern

Extract a subset of a point pattern, either by thinning the points or by trimming the window.

- Keywords
- spatial

##### Usage

```
subset.ppp(x, subset, window, drop, ...)
subset.ppp(x, subset, window)
x[subset]
x[subset,window]
```

##### Arguments

- x
- A two-dimensional point pattern.
An object of class
`"ppp"`

. - subset
- logical vector indicating which points should be retained.
- window
- window (an object of class
`"owin"`

) delineating a subset of the original observation window. - drop
- Ignored - this argument is required for consistency with other
methods for
`"["`

. - ...
- Ignored - this argument is required for consistency with other
methods for
`"["`

.

##### Details

This function takes performs either ``*thinning*''
(retaining/deleting some points of a point pattern)
or ``*trimming*'' (reducing the window of observation
to a smaller subregion and retaining only
those points which lie in the subregion).
The pattern will be ``thinned''
if `subset`

is specified. This should
be a logical vector of length equal to the number of points in the
point pattern `x`

.
The points `(x$x[i], x$y[i])`

for which
`subset[i]=TRUE`

will be retained, and the others
will be deleted.
The pattern will be ``trimmed''
if `window`

is specified. This should
be an object of class `owin`

specifying a window of observation
to which the point pattern `x`

will be
trimmed. The points of `x`

lying inside the new
`window`

will be retained.
Both ``thinning'' and ``trimming'' can be performed together.

Use the function `unmark`

to remove marks from a
marked point pattern.

##### Value

- A point pattern (of class
`"ppp"`

).

##### synopsis

subset.ppp(x, subset, window, drop, ...)

##### Warnings

The function does not check whether `window`

is a subset of
`x$window`

.

##### See Also

##### Examples

```
library(spatstat)
data(longleaf)
# Longleaf pines data
plot(longleaf)
# adult trees defined to have diameter at least 30 cm
adult <- (longleaf$marks >= 30)
longadult <- longleaf[adult]
# equivalent to: longadult <- subset.ppp(longleaf, subset=adult)
plot(longadult)
# note that the marks are still retained.
# Use unmark(longadult) to remove the marks
# New Zealand trees data
data(nztrees)
plot(nztrees) # plot shows a line of trees at the far right
abline(v=148, lty=2) # cut along this line
nzw <- owin(c(0,148),c(0,95)) # the subwindow
# trim dataset to this subwindow
nzsub <- nztrees[,nzw]
# equivalent to: nzsub <- subset.ppp(nztrees, window=nzw)
plot(nzsub)
# Redwood data
data(redwood)
plot(redwood)
# Random thinning: delete 60\% of data
retain <- (runif(redwood$n) < 0.4)
thinred <- redwood[retain]
plot(thinred)
# Lansing woods data - multitype points
data(lansing)
# hickory trees only
hick <- lansing[lansing$marks == "hickory", ]
# still a marked pattern -- remove marks
hick <- unmark(hick)
```

*Documentation reproduced from package spatstat, version 1.4-5, License: GPL version 2 or newer*