Any selected columns that contain dist_quantiles
will be "widened" with
the "taus" (quantile) serving as names and the values in the data frame.
When pivoting multiple columns, the original column name will be used as
a prefix.
Arguments
- .data
A data frame, or a data frame extension such as a tibble or epi_df.
- ...
<
tidy-select
> One or more unquoted expressions separated by commas. Variable names can be used as if they were positions in the data frame, so expressions likex:y
can be used to select a range of variables.
Examples
d1 <- c(dist_quantiles(1:3, 1:3 / 4), dist_quantiles(2:4, 1:3 / 4))
d2 <- c(dist_quantiles(2:4, 2:4 / 5), dist_quantiles(3:5, 2:4 / 5))
tib <- tibble::tibble(g = c("a", "b"), d1 = d1, d2 = d2)
pivot_quantiles_wider(tib, c("d1", "d2"))
#> # A tibble: 2 × 7
#> g d1_0.25 d1_0.5 d1_0.75 d2_0.4 d2_0.6 d2_0.8
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 a 1 2 3 2 3 4
#> 2 b 2 3 4 3 4 5
pivot_quantiles_wider(tib, dplyr::starts_with("d"))
#> # A tibble: 2 × 7
#> g d1_0.25 d1_0.5 d1_0.75 d2_0.4 d2_0.6 d2_0.8
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 a 1 2 3 2 3 4
#> 2 b 2 3 4 3 4 5
pivot_quantiles_wider(tib, d2)
#> # A tibble: 2 × 5
#> g d1 `0.4` `0.6` `0.8`
#> <chr> <dist> <dbl> <dbl> <dbl>
#> 1 a quantiles(2)[3] 2 3 4
#> 2 b quantiles(3)[3] 3 4 5