It computes summary statistics for a tsibble over calendar periods, usually used in combination of group_by.

tsummarise(.data, ...)

tsummarize(.data, ...)

Arguments

.data

A data frame (of tbl_ts class).

...

Name-value pairs of expressions. The index variable must be present in the calls, coupled with an index function, to carry out the calculation. The index functions that can be used, but not limited:

Examples

# Monthly counts across Sensors data(pedestrian) monthly_ped <- pedestrian %>% group_by(Sensor) %>% tsummarise( Year_Month = yearmonth(Date_Time), # Year_Month will be the new index Max_Count = max(Count), Min_Count = min(Count) ) monthly_ped
#> # A tsibble: 95 x 4 [1MONTH] #> # Keys: Sensor [4] #> # Groups: Sensor [4] #> Sensor Year_Month Max_Count Min_Count #> <chr> <mth> <dbl> <dbl> #> 1 Birrarung Marr 2015 Jan 5524 1.00 #> 2 Birrarung Marr 2015 Feb 10121 1.00 #> 3 Birrarung Marr 2015 Mar 9858 1.00 #> 4 Birrarung Marr 2015 Apr 7293 1.00 #> 5 Birrarung Marr 2015 May 5129 1.00 #> 6 Birrarung Marr 2015 Jun 7556 0 #> 7 Birrarung Marr 2015 Jul 11224 1.00 #> 8 Birrarung Marr 2015 Aug 5684 0 #> 9 Birrarung Marr 2015 Sep 7757 0 #> 10 Birrarung Marr 2015 Oct 7085 1.00 #> # ... with 85 more rows
index(monthly_ped)
#> <quosure> #> expr: ^Year_Month #> env: 0x11f988698
# Annual trips by Region and State ---- data(tourism) tourism %>% group_by(Region | State) %>% tsummarise(Year = lubridate::year(Quarter), Total = sum(Trips))
#> # A tsibble: 1,463 x 4 [1YEAR] #> # Keys: Region | State [77] #> # Groups: Region | State [77] #> Region State Year Total #> <chr> <chr> <dbl> <dbl> #> 1 Adelaide South Australia 1998 2226 #> 2 Adelaide South Australia 1999 2218 #> 3 Adelaide South Australia 2000 2418 #> 4 Adelaide South Australia 2001 2264 #> 5 Adelaide South Australia 2002 2275 #> 6 Adelaide South Australia 2003 2203 #> 7 Adelaide South Australia 2004 2437 #> 8 Adelaide South Australia 2005 2034 #> 9 Adelaide South Australia 2006 2225 #> 10 Adelaide South Australia 2007 2317 #> # ... with 1,453 more rows