powered by
This function takes a random sample of rows from a data frame, in analogy to the built-in function sample (which sadly does not accept a data frame).
sample
sample.df(df, size, replace=FALSE, sort=FALSE, prob=NULL)
A data frame containing the sampled rows of df, either their original order (sort=TRUE) or shuffled randomly (sort=FALSE).
df
sort=TRUE
sort=FALSE
a data frame to be sampled from
positive integer giving the number of rows to choose
Should sampling be with replacement?
Should rows in sample be sorted in original order?
a vector of probability weights for obtaining the elements of the vector being sampled
Stephanie Evert (https://purl.org/stephanie.evert)
Internally, rows are selected with the function sample.int. See its manual page for details on the arguments (except for sort) and implementation.
sample.int
sort
sample.df(BrownLOBPassives, 20, sort=TRUE)
Run the code above in your browser using DataLab