
Last chance! 50% off unlimited learning
Sale ends in
The methods below are convenience short-cuts to take samples from data frames and data sets. They result in a data frame or data set, respectively, the rows of which are a sample of the complete data frame/data set.
# S4 method for data.frame
sample(x, size, replace = FALSE, prob = NULL)
# S4 method for data.set
sample(x, size, replace = FALSE, prob = NULL)
# S4 method for importer
sample(x, size, replace = FALSE, prob = NULL)
a data frame or data set.
an (optional) numerical value, the sample size,
defaults to the total number of rows of x
.
a logical value, determines whether sampling takes place with or without replacement.
a vector of sampling probabities or NULL.
A data frame or data set.
# NOT RUN {
for(.i in 1:4)
print(sample(iris,5))
# }
Run the code above in your browser using DataLab