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 between 1-k. The second element is r + k, and so on.
sample_random(data, n, prop, by =NULL, weight =NULL)sample_systematic(data, n, r =NULL, by =NULL)
Arguments
data: A data frame. If data is a grouped_df, the operation will be performed on each group (stratified).
n, prop: Provide either n, the number of rows, or prop, the proportion of rows to select. If neither are supplied, n = 1 will be used.
by: A categorical variable to compute the sample by. It is a shortcut to dplyr::group_by() that allows to group the data by one categorical variable. If more than one grouping variable needs to be used, use dplyr::group_by() to pass the data grouped.
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, r is randomly selected between 1:k
Returns
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)