Learn R Programming

secr (version 5.0.0)

subset.traps: Subset traps Object

Description

Retain selected rows of a traps object.

Usage

# S3 method for traps
subset(x, subset = NULL, occasions = NULL, ...)
# S3 method for traps
split(x, f, drop = FALSE, prefix = "S", byoccasion = FALSE, ...)

Value

An object of class traps with only the requested subset of rows. Subsetting is applied to usage and covariates attributes if these are present.

Splitting with byoccasion = TRUE produces a list of traps objects, each with usage codes for a subset of occasions. Traps not used on any occasion within a session are automatically dropped from that session.

Arguments

x

traps object

subset

vector to subscript the rows of x

occasions

vector to subscript columns in usage(x)

...

arguments passed to other functions or to optional subset function (subset.traps)

f

factor or object that may be coerced to a factor

drop

logical indicating if levels that do not occur should be dropped (if f is a factor)

prefix

a character prefix to be used for component names when values of f are numeric

byoccasion

logical ; if TRUE then f is used to split occasions

Warning

split.traps does not work for mark--resight data.

Details

The subscripts in subset may be of type integer, character or logical as described in Extract. By default, all rows are retained.

In the case of `polygon' and `transect' detectors, subsetting is done at the level of whole polygons or transects. subset should therefore have the same length as levels(polyID(x)) or levels(transectID(x)).

split generates a list in which each component is a traps object. Each component corresponds to a level of f. The argument x of split cannot be a list (i.e. x must be a single-session traps object).

If the levels of f are numeric, from version 2.10.3 a leading zero is inserted in the names of the output list to maintain the sort order.

See Also

traps, rbind.traps

Examples

Run this code
## odd-numbered traps only, using modulo operator
temptrap <- make.grid(nx = 7, ny = 7)
t2 <- subset(temptrap, as.logical(1:nrow(temptrap) %% 2))
plot(t2)

## this works also for even number of rows, but must change 'outer' call
temptrap <- make.grid(nx = 8, ny = 8)
t3 <- subset(temptrap, !as.logical(outer(1:8,1:8,'+')%%2))
plot(t3)

Run the code above in your browser using DataLab