Skip to contents

Selected columns that contain quantile_pred will be "lengthened" with the quantile_levels in one column and the values in another. If multiple columns are selected, these will be prefixed with the column name.

Usage

pivot_quantiles_longer(.data, ...)

Arguments

.data

A data frame, or a data frame extension such as a tibble or epi_df.

...

<tidy-select> One unquoted expressions separated by commas. Variable names can be used as if they were positions in the data frame. Note that only one variable can be selected for this operation.

Value

An object of the same class as .data.

Examples

d1 <- quantile_pred(rbind(1:3, 2:4), 1:3 / 4)
d2 <- quantile_pred(rbind(2:4, 3:5), 2:4 / 5)
tib <- tibble(g = c("a", "b"), d1 = d1, d2 = d2)

pivot_quantiles_longer(tib, "d1")
#> # A tibble: 6 × 4
#>   g            d2 d1_value d1_quantile_level
#>   <chr> <qtls(3)>    <int>             <dbl>
#> 1 a         [2.5]        1              0.25
#> 2 a         [2.5]        2              0.5 
#> 3 a         [2.5]        3              0.75
#> 4 b         [3.5]        2              0.25
#> 5 b         [3.5]        3              0.5 
#> 6 b         [3.5]        4              0.75
pivot_quantiles_longer(tib, dplyr::ends_with("1"))
#> # A tibble: 6 × 4
#>   g            d2 d1_value d1_quantile_level
#>   <chr> <qtls(3)>    <int>             <dbl>
#> 1 a         [2.5]        1              0.25
#> 2 a         [2.5]        2              0.5 
#> 3 a         [2.5]        3              0.75
#> 4 b         [3.5]        2              0.25
#> 5 b         [3.5]        3              0.5 
#> 6 b         [3.5]        4              0.75
pivot_quantiles_longer(tib, d2)
#> # A tibble: 6 × 4
#>   g            d1 d2_value d2_quantile_level
#>   <chr> <qtls(3)>    <int>             <dbl>
#> 1 a           [2]        2               0.4
#> 2 a           [2]        3               0.6
#> 3 a           [2]        4               0.8
#> 4 b           [3]        3               0.4
#> 5 b           [3]        4               0.6
#> 6 b           [3]        5               0.8