Tidy temporal data with tsibble
Today let's understand tsibble, the data structure R uses for time series, with a real example.
Riverside Bike Share runs two rental kiosks, one at Riverside and one Downtown. Here is each kiosk's daily rentals for June and July 2024, 61 days, one dot per day.
Riverside's dots run all the way across, one for every day. Downtown's row of dots breaks three times, on June 11, 18 and 25. That break is the whole problem this lesson solves: a plain data frame cannot tell you it has a gap, and a tsibble can.
A data frame that happens to have a time column
Before tsibble can help, look at what an ordinary data frame gives you for free, and what it does not.
Riverside Bike Share logs one row per kiosk per day: which kiosk, which date, how many rentals. Build that log for June and July 2024, 61 days at each kiosk, then look at its shape.
That's 119 rows: 61 for Riverside and 58 for Downtown. Downtown is short because its payment terminal failed to restart on three Tuesdays and logged nothing those days.
But bike_long is a plain data frame. R treats date as just another column, exactly like site or rentals. Nothing about it says the rows are in time order, or that the 61 Riverside rows and 58 Downtown rows form two separate ongoing series. You could shuffle every row in bike_long and R would not object, even though shuffling a time series destroys the one thing that makes it a time series: the order the values arrived in.
The gap is easy to miss too. Nothing in bike_long flags that Downtown's log is short compared to Riverside's, or which dates are missing. You would have to go looking for it by hand. That is exactly what tsibble is built to catch.