View source: R/resample_boot.R
resample_boot | R Documentation |
Generate data resamples using bootstrap
resample_boot(data, n = 10, ...)
data |
data.frame, the data to resample. |
n |
integer, number of bootstraps. |
... |
unquoted names of columns of .data to stratify by. Usually they are discrete variables. |
A tibble with columns
train : an object of class modelr::resample. The boostrapped data.
val : an object of class modelr::resample. The out-of-bag data (i.e. the rows of .data not selected in the current bootstrap).
boot : integer, the bootstrap number.
resample_boot(mtcars, n=2)
rs <- resample_boot(mtcars, n=2)
data.frame(rs$train[1])
# = some rows are repeated
data.frame(rs$val[1])
# = all these rows are not above
# stratified bootstrap
rs <- resample_boot(mtcars, n=10)
rss <- resample_boot(mtcars, n=10, gear)
sapply(rs$train, function(x) {sum(data.frame(x)$gear==4)})
# = variable number of occurrence of gear==4 in the training set
sapply(rss$train, function(x) {sum(data.frame(x)$gear==4)})
# = reliable number of gear==4 in the training set
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.