sample.rows {dodoR} | R Documentation |
sample.rows
takes a sample of the specified size from the rows of x
using either with or without replacement
sample.rows(x, size, replace = F, prob = NULL)
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. |
It basically does the same as sample
, but returns row samples instead
of column samples.
A data.frame
containing size
rows extracted of
x
.
Douglas De Rizzo Meneghetti
http://stackoverflow.com/questions/8273313/random-rows-in-dataframe-in-r
##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