Learn R Programming

simFrame (version 0.1.2)

sampling: Random sampling

Description

Functions for random sampling.

Usage

srs(N, size, replace = FALSE)

ups(N, size, prob, replace = FALSE)

Arguments

N
a non-negative integer giving the number of observations from which to sample.
size
a non-negative integer giving the number of observations to sample.
prob
a numeric vector giving the probability weights.
replace
a logical indicating whether sampling should be performed with or without replacement.

Value

  • An integer vector giving the indices of the sampled observations.

Details

srs and ups are wrappers for simple random sampling and unequal probability sampling, respectively. Both functions make use of sample.

See Also

SampleControl, setup, sample

Examples

Run this code
## simple random sampling without replacement
srs(10, 5)

## simple random sampling with replacement
srs(5, 10, replace = TRUE)

## unequal probability sampling without replacement
ups(10, 5, prob = 1:10)

## unequal probability sampling with replacement
ups(5, 10, prob = 1:5, replace = TRUE)

Run the code above in your browser using DataLab