utils_samples {metan}R Documentation

Random Sampling

Description

Usage

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

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)

[Package metan version 1.18.0 Index]