Time Series Summaries
Seasonal Total
Group Ordered Months
Seasonal summaries group neighboring observations into fixed-size periods.
Program
Play the script to change the group size and see the final period total.
seasonal_total.R
group_size <-
month <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun")
value <- c(8, 10, 13, 15, 17, 20)
group <- ceiling(seq_along(value) / group_size)
totals <- tapply(value, group, sum)
last_total <- totals[[length(totals)]]
label <- paste("last", last_total, sep = ":")
cat(label, "\n", sep = "")
group_size <-
month <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun")
value <- c(8, 10, 13, 15, 17, 20)
group <- ceiling(seq_along(value) / group_size)
totals <- tapply(value, group, sum)
last_total <- totals[[length(totals)]]
label <- paste("last", last_total, sep = ":")
cat(label, "\n", sep = "")
group_size <-
month <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun")
value <- c(8, 10, 13, 15, 17, 20)
group <- ceiling(seq_along(value) / group_size)
totals <- tapply(value, group, sum)
last_total <- totals[[length(totals)]]
label <- paste("last", last_total, sep = ":")
cat(label, "\n", sep = "")
period groups
`ceiling(seq_along(value) / group_size)` assigns each row to a period.
aggregation
`tapply(value, group, sum)` totals each period.
latest period
The last total summarizes the newest group.