Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

sample2

Takes samples in the usual manner


Description

The standard sample function in R samples from n numbers when x = n. This is unwanted behavior when the size of the vector to sample from changes dynamically. This is corrected in sample2

Usage

sample2(x, size, replace = FALSE, prob = NULL)

Arguments

x

A vector of one or more elements

size

A non-negative integer giving the number of items to choose.

replace

Should sampling be with replacement?

prob

A vector of probability weights for obtaining the elements of the vector being sampled.

Value

sam

A vector of length size that is sampled from x.

Author(s)

Rampal S. Etienne

Examples

sample(x = 10,size = 5,replace = TRUE)
sample2(x = 10,size = 5,replace = TRUE)

DDD

Diversity-Dependent Diversification

v4.4.1
GPL-3
Authors
Rampal S. Etienne & Bart Haegeman
Initial release
2021-01-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.