This method uses gather
on an rset
object to stack all of
the non-ID or split columns in the data and is useful for
stacking model evaluation statistics. The resulting data frame
has a column based on the column names of data
and another for
the values. This method is now deprecated in favor of using
tidyr::pivot_longer()
directly.
# S3 method for rset
gather(
data,
key = NULL,
value = NULL,
...,
na.rm = TRUE,
convert = FALSE,
factor_key = TRUE
)
An rset
object.
Not specified in this method and will be ignored. Note that this means that selectors are ignored if they are passed to the function.
If TRUE
, will remove rows from output where the
value column in NA
.
If TRUE
will automatically run
type.convert()
on the key column. This is useful if the column
names are actually numeric, integer, or logical.
If FALSE, the default, the key values will be
stored as a character vector. If TRUE
, will be stored as a
factor, which preserves the original ordering of the columns.
library(rsample)
cv_obj <- vfold_cv(mtcars, v = 10)
cv_obj$lm_rmse <- rnorm(10, mean = 2)
cv_obj$nnet_rmse <- rnorm(10, mean = 1)
## now deprecated for rset objects:
## gather(cv_obj)
## instead of gather, use tidyr::pivot_longer:
library(tidyr)
library(dplyr)
cv_obj %>%
select(-splits) %>%
pivot_longer(-id)
#> # A tibble: 20 × 3
#> id name value
#> <chr> <chr> <dbl>
#> 1 Fold01 lm_rmse 0.206
#> 2 Fold01 nnet_rmse -0.354
#> 3 Fold02 lm_rmse 1.61
#> 4 Fold02 nnet_rmse 3.37
#> 5 Fold03 lm_rmse 0.622
#> 6 Fold03 nnet_rmse 0.464
#> 7 Fold04 lm_rmse 1.96
#> 8 Fold04 nnet_rmse 0.628
#> 9 Fold05 lm_rmse 1.92
#> 10 Fold05 nnet_rmse 1.55
#> 11 Fold06 lm_rmse 1.27
#> 12 Fold06 nnet_rmse 1.25
#> 13 Fold07 lm_rmse 2.41
#> 14 Fold07 nnet_rmse 0.162
#> 15 Fold08 lm_rmse 1.94
#> 16 Fold08 nnet_rmse 2.84
#> 17 Fold09 lm_rmse 2.88
#> 18 Fold09 nnet_rmse 1.03
#> 19 Fold10 lm_rmse 1.97
#> 20 Fold10 nnet_rmse 0.311