sample: Random Samples and Permutations

Description Usage Arguments Value Author(s) See Also Examples

Description

sample takes a sample of the specified size from the elements of x either with or without replacement. Unlike base::sample, sample handles data frames in a reasonable manner.

Usage

1
sample(x, size, replace = FALSE, prob = NULL)

Arguments

x

an integer, vector, or data frame.

size

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

replace

logical indicating whether sampling should be performed with or without replacement.

prob

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

Value

If x is a vector, a vector of length size with elements drawn from x. If x is a integer, a vector of length size with elements drawn from 1:x. If x is a data frame, a data frame with size rows, all the columns in x and one additional column indicating the location of the selected rows in x.

Author(s)

Randall Pruim (rpruim@calvin.edu)

See Also

sample

Examples

1
2
x <- data.frame(letter=letters[1:10], number=1:10)
sample(x,3)

abd documentation built on May 2, 2019, 4:46 p.m.