Create monthly pivot summary

monthly_pivot(
  data,
  date,
  group_by,
  values_from,
  calc = sum,
  na.rm = TRUE,
  total = FALSE,
  total_name = NULL
)

Arguments

data

data.frame

date

date column name

group_by

column(s) to group the data by

values_from

values column

calc

calculation function (default sum)

na.rm

remove NAs in calculation (default is TRUE)

total

add total column (default FALSE)

total_name

name of total column

Value

Examples

monthly_pivot(dplyr::filter(hflights, Date >= '2011-10-01'), date = 'Date', group_by = c("Origin", "Dest"), values_from = "DepDelay", total = TRUE)
#> # A tibble: 144 x 6 #> Origin Dest `2011-10` `2011-11` `2011-12` Total #> <chr> <chr> <int> <int> <int> <int> #> 1 HOU ABQ 1169 705 800 2674 #> 2 HOU ATL 1036 1014 688 2738 #> 3 HOU AUS 1102 1021 1472 3595 #> 4 HOU BHM 680 512 574 1766 #> 5 HOU BKG -133 72 -16 -77 #> 6 HOU BNA 652 936 1085 2673 #> 7 HOU BWI 842 750 821 2413 #> 8 HOU CHS 124 105 222 451 #> 9 HOU CRP 1319 1168 1656 4143 #> 10 HOU DAL 5784 4612 5657 16053 #> # ... with 134 more rows