How to convert a data frame imported from csv file to tsibble ? (for time series analysis)

This is the imported df

There is an example using monthly data here: 2.1 tsibble objects | Forecasting: Principles and Practice (3rd ed)

Generally, you need the as_tsibble() function from the tsibble package, and possibly a function to convert the time index from character into a time or date class. With your data, you can use yearmonth(), also from the tsibble package.

library(tsibble)
df %>%
  mutate(Year_Month = yearmonth(Year_Month)) %>%
  as_tsibble(index = Year_Month)
1 Like