Randomly select a proportion with replacement
iris %>%
slice_sample(prop = 0.8, replace = T)
# A tibble: 120 × 5
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
<dbl> <dbl> <dbl> <dbl> <fct>
1 5.3 3.7 1.5 0.2 setosa
2 5.7 2.6 3.5 1 versicolor
3 5.5 2.5 4 1.3 versicolor
4 5.5 2.3 4 1.3 versicolor
5 6.2 2.2 4.5 1.5 versicolor
6 4.4 2.9 1.4 0.2 setosa
7 5.4 3.9 1.7 0.4 setosa
8 5 3.6 1.4 0.2 setosa
9 4.5 2.3 1.3 0.3 setosa
10 6.9 3.1 5.4 2.1 virginica
# … with 110 more rows
Randomly select a number of rows
iris %>%
slice_sample(n = 5)
# A tibble: 5 × 5
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
<dbl> <dbl> <dbl> <dbl> <fct>
1 5 3.5 1.3 0.3 setosa
2 6.9 3.1 5.1 2.3 virginica
3 6.4 3.1 5.5 1.8 virginica
4 4.4 3.2 1.3 0.2 setosa
5 5.8 2.8 5.1 2.4 virginica
Create bootstrapped datasets (and store in list-column format)
enframe(
map(1:10, # Number of bootstrapped datasets to create
~ iris %>% # Original dataset
slice_sample(prop = 1, replace = TRUE)),
name = "bootstrap_id",
value = "bootstrap_resamples")
# A tibble: 10 × 2
bootstrap_id bootstrap_resamples
<int> <list>
1 1 <df [150 × 5]>
2 2 <df [150 × 5]>
3 3 <df [150 × 5]>
4 4 <df [150 × 5]>
5 5 <df [150 × 5]>
6 6 <df [150 × 5]>
7 7 <df [150 × 5]>
8 8 <df [150 × 5]>
9 9 <df [150 × 5]>
10 10 <df [150 × 5]>