Skip to contents

Calculate column differences

Usage

column_diffs(
  data,
  prefix.pattern = NULL,
  include.first = TRUE,
  suffix.out = "_diff"
)

Arguments

data

tibble

prefix.pattern

tidyselect style column selection. Default is NULL

include.first

include first column. Default is TRUE

suffix.out

suffix for output columns

Value

tibble

Examples

tibble::tibble(a=sample(1:10,5),b=sample(1:10,5),c=sample(1:10,5)) |>
(\(.x) list(.x,column_diffs(.x)))()
#> [[1]]
#> # A tibble: 5 × 3
#>       a     b     c
#>   <int> <int> <int>
#> 1     7     6     2
#> 2     5     9     7
#> 3     6     5     3
#> 4    10     8     6
#> 5     4     7     8
#> 
#> [[2]]
#> # A tibble: 5 × 3
#>       a a_diff b_diff
#>   <int>  <int>  <int>
#> 1     7      1      4
#> 2     5      4      2
#> 3     6      1      2
#> 4    10      2      2
#> 5     4      3      1
#>