tsibble-tidyverse {tsibble} | R Documentation |
Tidyverse methods for tsibble
Description
Current dplyr verbs that tsibble has support for:
-
dplyr::select()
,dplyr::transmute()
,dplyr::mutate()
,dplyr::relocate()
,dplyr::summarise()
,dplyr::group_by()
-
dplyr::left_join()
,dplyr::right_join()
,dplyr::full_join()
,dplyr::inner_join()
,dplyr::semi_join()
,dplyr::anti_join()
,dplyr::nest_join()
Current tidyr verbs that tsibble has support for:
Column-wise verbs
The index variable cannot be dropped for a tsibble object.
When any key variable is modified, a check on the validity of the resulting tsibble will be performed internally.
Use
as_tibble()
to convert tsibble to a general data frame.
Row-wise verbs
A warning is likely to be issued, if observations are not arranged in past-to-future order.
Join verbs
Joining with other data sources triggers the check on the validity of the resulting tsibble.
Examples
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)