tempcapt <- sim.capthist (make.grid(nx = 6, ny = 6), noccasions = 6)
summary(subset(tempcapt, occasions = c(1,3,5)))
## Consider `proximity' detections at a random subset of detectors
## This would not make sense for `multi' detectors, as the
## excluded detectors influence detection probabilities in
## sim.capthist.
tempcapt2 <- sim.capthist (make.grid(nx = 6, ny = 6,
detector = "proximity"), noccasions = 6)
tempcapt3 <- subset(tempcapt2, traps = sample(1:36, 18,
replace = FALSE))
summary(tempcapt3)
plot(tempcapt3)
tempcapt4 <- split (tempcapt2, f = sample (c("A","B"),
nrow(tempcapt2), replace = TRUE))
summary(tempcapt4)
## Split out captures on alternate rows of a grid
tempcapt5 <- split(captdata, f = rep(1:2, 50), bytrap = TRUE)
summary(tempcapt5)
## Divide one session into two by occasion
tempcapt6 <- split(captdata, f = factor(c(1,1,2,2,2)), byoccasion = TRUE)
summary(tempcapt6)
## Applying a covariate criterion across all sessions of a
## multi-session capthist object e.g. selecting male ovenbirds from the
## 2005--2009 ovenCH dataset. We include a restriction on occasions
## to demonstrate the use of 'MoreArgs'. Note that mapply() creates a
## list, and the class of the output must be restored manually.
ovenCH.males <- mapply(subset, ovenCH,
subset = lapply(ovenCH, function(x) covariates(x)$Sex == "M"),
MoreArgs = list(occasions = 1:5))
class(ovenCH.males) <- class(ovenCH)
summary(ovenCH.males, terse = TRUE)
## A simpler approach using a function to define subset
subsetfn <- function(x, sex) covariates(x)$Sex == sex
ovenCH.males <- subset(ovenCH, subset = subsetfn, sex = "M")
summary(ovenCH.males, terse = TRUE)
Run the code above in your browser using DataLab