For a data set, add_resample_id() will add at least one new column that identifies which resample that the data came from. In most cases, a single column is added but for some resampling methods, two or more are added.

add_resample_id(.data, split, dots = FALSE)

Arguments

.data

A data frame

split

A single rset object.

dots

A single logical: should the id columns be prefixed with a "." to avoid name conflicts with .data?

Value

An updated data frame.

See also

labels.rsplit

Examples

#> #> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’: #> #> filter, lag
#> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union
set.seed(363) car_folds <- vfold_cv(mtcars, repeats = 3) analysis(car_folds$splits[[1]]) %>% add_resample_id(car_folds$splits[[1]]) %>% head()
#> mpg cyl disp hp drat wt qsec vs am gear carb id #> Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 Repeat1 #> Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 Repeat1 #> Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 Repeat1 #> Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 Repeat1 #> Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2 Repeat1 #> Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1 Repeat1 #> id2 #> Mazda RX4 Fold01 #> Mazda RX4 Wag Fold01 #> Datsun 710 Fold01 #> Hornet 4 Drive Fold01 #> Hornet Sportabout Fold01 #> Valiant Fold01
car_bt <- bootstraps(mtcars) analysis(car_bt$splits[[1]]) %>% add_resample_id(car_bt$splits[[1]]) %>% head()
#> mpg cyl disp hp drat wt qsec vs am gear carb #> Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 #> Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 #> Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 #> Chrysler Imperial.1 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 #> Volvo 142E.1 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 #> id #> Toyota Corona Bootstrap01 #> Mazda RX4 Bootstrap01 #> Chrysler Imperial Bootstrap01 #> Volvo 142E Bootstrap01 #> Chrysler Imperial.1 Bootstrap01 #> Volvo 142E.1 Bootstrap01