Last chance! 50% off unlimited learning
Sale ends in
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)
An object of the same type as data
.
A data frame. If data
is a grouped_df
, the operation will be
performed on each group (stratified).
Provide either n
, the number of rows, or prop
, the
proportion of rows to select. If neither are supplied, n = 1
will be
used.
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.
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.
The starting element. By default, r
is randomly selected between
1:k
library(metan)
sample_random(data_ge, n = 5)
sample_random(data_ge,
n = 3,
by = ENV)
sample_systematic(data_g, n = 6)
Run the code above in your browser using DataLab