| utils_samples {metan} | R Documentation |
Random Sampling
Description
-
sample_random()performs Simple Random Sampling or Stratified Random Sampling -
sample_systematic()performs systematic sampling. In this case, a regular interval of size k (k = floor(N/n)) is generated considering the population size (N) and desired sample size (n). Then, the starting member (r) is randomly chosen between1-k. The second element isr+k, and so on.
Usage
sample_random(data, n, prop, by = NULL, weight = NULL)
sample_systematic(data, n, r = NULL, by = NULL)
Arguments
data |
A data frame. If |
n, prop |
Provide either |
by |
A categorical variable to compute the sample by. It is a
shortcut to |
weight |
Sampling weights. This must evaluate to a vector of non-negative numbers the same length as the input. Weights are automatically standardised to sum to 1. |
r |
The starting element. By default, |
Value
An object of the same type as data.
Examples
library(metan)
sample_random(data_ge, n = 5)
sample_random(data_ge,
n = 3,
by = ENV)
sample_systematic(data_g, n = 6)