library(dplyr, warn.conflicts = FALSE)
# `summarise()` a tsibble always aggregates over time
# Sum over sensors
pedestrian %>%
index_by() %>%
summarise(Total = sum(Count))
# shortcut
pedestrian %>%
summarise(Total = sum(Count))
# Back to tibble
pedestrian %>%
as_tibble() %>%
summarise(Total = sum(Count))
library(tidyr)
stocks <- tsibble(
time = as.Date("2009-01-01") + 0:9,
X = rnorm(10, 0, 1),
Y = rnorm(10, 0, 2),
Z = rnorm(10, 0, 4)
)
(stocksm <- stocks %>%
pivot_longer(-time, names_to = "stock", values_to = "price"))
stocksm %>%
pivot_wider(names_from = stock, values_from = price)
Run the code above in your browser using DataLab