| subset.ppp {spatstat} | R Documentation |
Extract or replace a subset of a point pattern. Extraction has the effect of thinning the points and/or or trimming the window.
## S3 method for class 'ppp': x[subset, window] ## S3 method for class 'ppp': x[subset] ## S3 method for class 'ppp': x[, window] ## S3 method for class 'ppp': x[subset, window] <- value ## S3 method for class 'ppp': x[subset] <- value ## S3 method for class 'ppp': x[, window] <- value
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.
|
value |
Replacement value for the subset. A point pattern. |
|
These functions extract a designated subset of a point pattern, or replace the designated subset with another point pattern.
The function [.ppp is a method for [ for the
class "ppp". It extracts a designated subset of a point pattern,
either by ``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) or both.
The pattern will be ``thinned''
if subset is specified. The points designated by subset
will be retained. Here subset can be a numeric vector
of positive indices (identifying the points to be retained),
a numeric vector of negative indices (identifying the points
to be deleted) or a logical vector of length equal to the number
of points in the point pattern x. In the latter case,
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.
The function [<-.ppp is a method for [<- for the
class "ppp". It replaces the designated
subset with the point pattern value.
The subset of x to be replaced is designated by
the arguments subset and window as above.
The replacement point pattern value must lie inside the
window of the original pattern x.
The ordering of points in x will be preserved
if the replacement pattern value has the same number of points
as the subset to be replaced. Otherwise the ordering is
unpredictable.
Use the function unmark to remove marks from a
marked point pattern.
Use the function split.ppp to select those points
in a marked point pattern which have a specified mark.
A point pattern (of class "ppp").
The function does not check whether window is a subset of
x$window. Nor does it check whether value lies
inside x$window.
Adrian Baddeley adrian@maths.uwa.edu.au http://www.maths.uwa.edu.au/~adrian/ and Rolf Turner rolf@math.unb.ca http://www.math.unb.ca/~rolf
ppp.object,
owin.object,
unmark,
split.ppp,
cut.ppp
data(longleaf)
# Longleaf pines data
## Not run:
plot(longleaf)
## End(Not run)
# 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)
## Not run:
plot(longadult)
## End(Not run)
# note that the marks are still retained.
# Use unmark(longadult) to remove the marks
# New Zealand trees data
data(nztrees)
## Not run:
plot(nztrees) # plot shows a line of trees at the far right
abline(v=148, lty=2) # cut along this line
## End(Not run)
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)
## Not run:
plot(nzsub)
## End(Not run)
# Redwood data
data(redwood)
## Not run:
plot(redwood)
## End(Not run)
# Random thinning: delete 60% of data
retain <- (runif(redwood$n) < 0.4)
thinred <- redwood[retain]
## Not run:
plot(thinred)
## End(Not run)
# Scramble 60% of data
modif <- (runif(redwood$n) < 0.6)
scramble <- function(x) { runifpoint(x$n, x$window) }
redwood[modif] <- scramble(redwood[modif])
# Lansing woods data - multitype points
data(lansing)
# hickory trees only
hick <- lansing[lansing$marks == "hickory", ]
# still a marked pattern -- remove marks
hick <- unmark(hick)
# scramble the hickories
lansing[lansing$marks == "hickory"] <- scramble(hick)