# A tsibble: 5 x 2 [1Y]
Year Observation
<int> <dbl>
1 2015 123
2 2016 39
3 2017 78
4 2018 52
5 2019 110
Or from an existing data frame
y <-tibble(Year =2015:2019,Observation =c(123, 39, 78, 52, 110))y <- y |>as_tsibble(index = Year)y
# A tsibble: 5 x 2 [1Y]
Year Observation
<int> <dbl>
1 2015 123
2 2016 39
3 2017 78
4 2018 52
5 2019 110
tsibble
From a csv file. For a tsibble to be valid, it requires a unique index for each combination of keys. The tsibble() or as_tsibble() function will return an error if this is not true.
prison <- readr::read_csv("https://OTexts.com/fpp3/extrafiles/prison_population.csv")prison <- prison %>%# you need to declare the time objectmutate(Quarter =yearquarter(Date)) %>%select(-Date) %>%# note that the key can be multivariateas_tsibble(key =c(State, Gender, Legal, Indigenous),index = Quarter)prison
# A tsibble: 58 x 12 [1Y]
# Key: Country [1]
Country Code Year GDP Growth CPI Imports Exports Population `5-MA`
<fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Sweden SWE 1960 1.48e10 NA 9.21 23.4 23.0 7484656 NA
2 Sweden SWE 1961 1.61e10 5.68 9.41 21.7 22.3 7519998 NA
3 Sweden SWE 1962 1.75e10 4.26 9.86 21.4 21.9 7561588 22.3
4 Sweden SWE 1963 1.90e10 5.33 10.1 21.5 21.9 7604328 22.1
5 Sweden SWE 1964 2.11e10 6.82 10.5 21.9 22.3 7661354 21.9
6 Sweden SWE 1965 2.33e10 3.82 11.0 22.5 21.9 7733853 21.7
7 Sweden SWE 1966 2.53e10 2.09 11.7 21.9 21.4 7807797 21.7
8 Sweden SWE 1967 2.75e10 3.37 12.2 21.0 21.1 7867931 21.8
9 Sweden SWE 1968 2.91e10 3.64 12.5 21.6 21.6 7912273 21.9
10 Sweden SWE 1969 3.16e10 5.01 12.8 23.0 22.8 7968072 22.2
# ℹ 48 more rows
# ℹ 2 more variables: `7-MA` <dbl>, `9-MA` <dbl>