how to create a yearly tsibble

Hi All

I understand how to create a monthly tsibble and quaterly

tibble_example %>% 
    mutate(Month = yearmonth(Month)) %>%
  as_tsibble(index = Month)
 tibble_quaterly <- read_csv("data/prison_population.csv")
  tibble_quaterly %>% 
  mutate(Quarter = yearquarter(Date)) %>%
  as_tsibble(key = c(State, Gender, Legal, Indigenous),index = Quarter) %>% 
  print()

According to the book we would use start:end but i cannot work out the code
how do you create a YEARLY tsibble from an excel spreadsheet xlsx?
can you give me an example that contains several keys¿?
also is there a good guide/Manual that contains examples for Tsibbles? ( I have so many questions..)
thanks in advance!
Tony

Here is a simple example using a csv file.

library(fpp3)

readr::read_csv("https://github.com/tidyverts/tsibbledata/raw/master/data-raw/pelt/lynxhare.csv") %>%
  as_tsibble(index = Year)

#> # A tsibble: 91 x 3 [1Y]
#>     Year  Hare  Lynx
#>    <dbl> <dbl> <dbl>
#>  1  1845  19.6 30.1 
#>  2  1846  19.6 45.2 
#>  3  1847  19.6 49.2 
#>  4  1848  12.0 39.5 
#>  5  1849  28.0 21.2 
#>  6  1850  58    8.42
#>  7  1851  74.6  5.56
#>  8  1852  75.1  5.08
#>  9  1853  88.5 10.2 
#> 10  1854  61.3 19.6 
#> # … with 81 more rows

Created on 2022-12-01 with reprex v2.0.2

The tsibble manual is available at https://tsibble.tidyverts.org.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.