Skip to contents

Selected columns that contain dist_quantiles will be "lengthened" with the quantile levels serving as 1 column and the values as another. If multiple columns are selected, these will be prefixed with the column name.

Usage

pivot_quantiles_longer(.data, ..., .ignore_length_check = FALSE)

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 like x:y can be used to select a range of variables.

.ignore_length_check

If multiple columns are selected, as long as each row has contains the same number of quantiles, the result will be reasonable. But if, for example, var1[1] has 5 quantiles while var2[1] has 7, then the only option would be to recycle everything, creating a very long result. By default, this would throw an error. But if this is really the goal, then the error can be bypassed by setting this argument to TRUE. The quantiles in the first selected column will vary the fastest.

Value

An object of the same class as .data.

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(g = c("a", "b"), d1 = d1, d2 = d2)

pivot_quantiles_longer(tib, "d1")
#> # A tibble: 6 × 4
#>   g     values quantile_levels                d2
#>   <chr>  <dbl>           <dbl>            <dist>
#> 1 a          1            0.25 quantiles(2.5)[3]
#> 2 a          2            0.5  quantiles(2.5)[3]
#> 3 a          3            0.75 quantiles(2.5)[3]
#> 4 b          2            0.25 quantiles(3.5)[3]
#> 5 b          3            0.5  quantiles(3.5)[3]
#> 6 b          4            0.75 quantiles(3.5)[3]
pivot_quantiles_longer(tib, dplyr::ends_with("1"))
#> # A tibble: 6 × 4
#>   g     values quantile_levels                d2
#>   <chr>  <dbl>           <dbl>            <dist>
#> 1 a          1            0.25 quantiles(2.5)[3]
#> 2 a          2            0.5  quantiles(2.5)[3]
#> 3 a          3            0.75 quantiles(2.5)[3]
#> 4 b          2            0.25 quantiles(3.5)[3]
#> 5 b          3            0.5  quantiles(3.5)[3]
#> 6 b          4            0.75 quantiles(3.5)[3]
pivot_quantiles_longer(tib, d1, d2)
#> # A tibble: 6 × 5
#>   g     d1_values d1_quantile_levels d2_values d2_quantile_levels
#>   <chr>     <dbl>              <dbl>     <dbl>              <dbl>
#> 1 a             1               0.25         2                0.4
#> 2 a             2               0.5          3                0.6
#> 3 a             3               0.75         4                0.8
#> 4 b             2               0.25         3                0.4
#> 5 b             3               0.5          4                0.6
#> 6 b             4               0.75         5                0.8