sample.rows {dodoR}R Documentation

Random Samples of Rows

Description

sample.rows takes a sample of the specified size from the rows of x using either with or without replacement

Usage

sample.rows(x, size, replace = F, prob = NULL)

Arguments

x

Either a vector of one or more elements from which to choose, or a positive integer.

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.

Details

It basically does the same as sample, but returns row samples instead of column samples.

Value

A data.frame containing size rows extracted of x.

Author(s)

Douglas De Rizzo Meneghetti

References

http://stackoverflow.com/questions/8273313/random-rows-in-dataframe-in-r

Examples

##Sample 5 random rows form the cars dataset
sample.rows(x = cars, size = 5)
##    speed dist
## 5      8   16
## 7     10   18
## 8     10   26
## 12    12   14
## 26    15   54

[Package dodoR version 1.0 Index]