sample: Take a random sample from a vector.

View source: R/sample.R

sampleR Documentation

Take a random sample from a vector.

Description

Take a random sample from a vector.

Usage

sample(x, size = vec_size(x), replace = FALSE, w = NULL)

Arguments

x

A vector.

size

Number of samples to take, Defaults to the size of x, generating a random permutation.

replace

Should samples be taken with or without replacement?

w

Optionally, a vector of weights. If provided should be a numeric vector the same size as x.

Examples

sample(1:5)
sample(1:100, 10)
sample(1:10, 100, replace = TRUE)

# samples of data frames are taken row wise, making it easy to
# do bootstrapping
sample(iris, 10, replace = TRUE)

# Unlike base::sample(), this is safe to use with inputs of length 1
sample(3:5)
sample(4:5)
sample(5:5)
base::sample(5:5)

tidyverse/funs documentation built on May 21, 2022, 12:12 p.m.