subsample: Sample a random subset of a dataframe containing presence and...

Description Usage Arguments Value See Also Examples

Description

Extract a random subset of n records from data, ensuring that there are at least minimum presence and absence records in the subset. The presence/absence column is identified by prescol.

Usage

1
subsample(data, n, minimum = c(5, 5), prescol = 1, replace = FALSE, max_tries = 10)

Arguments

data

A dataframe or matrix.

n

The number of records required in the subset.

minimum

An integer vector of length two giving the minimum number of presence (element one) and absence (element two) records in the subset.

prescol

An integer giving the column number for the presence/absence code (containing 1s for presences and 0s for absences.)

replace

Whether to sample with replacement.

max_tries

How many times to try the subsampling with minimum number of presences and absences before stopping with an error.

Value

A dataframe or matrix (whichever data was).

See Also

sample

Examples

1
2
3
4
5
6
n <- 100
dat <- data.frame(y = rbinom(n, 1, 0.2),
                  x = rnorm(n),
                  z = rnorm(n))
sub <- subsample(dat, 10, minimum = c(3, 3), prescol = 1)
sub

SEEG-Oxford/seegSDM documentation built on May 9, 2019, 11:08 a.m.