Get startedGet started for free

Time series attributes

1. Time series attributes

Welcome back!

2. Temporal attributes

Time series objects in R contain key attributes, known as "temporal attributes", which describe aspects of the time-based information found within, such as the beginning and end of the data. One common use of temporal attributes is to get an idea of the "extent" of our data in time. For example, certain surveys can last for decades; it's important to at least know when they start and finish! Temporal attributes are also crucial when combining multiple time series. We might encounter difficulties when merging overlapping time series; for example, time series A and B have regions that overlap. When we try to combine these, there is an issue: in the area that overlaps, what data do we use: A or B? We'll talk about the solution for this later in the chapter!

3. Temporal attributes

The first temporal attribute we'll talk about is the start point, which represents the time of the earliest observation and can be accessed with the start function from base R. Our output here can be interpreted as "Year 1949, Month 1" – January 1949.

4. Temporal attributes

The end point of the data – the point in time of the final observation – is found with the end function, like so: Here, I've called the end function on a different time series, hence the different output. But what does "1998 point 646" even mean? Sometimes, a time series uses a so-called "decimal date" as its index; decimal dates are used to divide a year into even parts. Quarters of a year, for example, could be represented with point 0, point 25, point 5, and point 75. Thankfully, lubridate has the date_decimal function that converts numeric decimal dates into more human-legible POSIXct objects, formatted in the ISO 8601 standard. Decimal dates are useful in creating time series with evenly-spaced intervals; more on that in a bit!

5. Temporal attributes

Finally, there's the frequency of the data; this represents how often our data are sampled within a year. For example, data sampled every month would have a frequency of twelve. We can use the frequency function on a time series object to determine the sampling frequency. Here, 260 means that our data was sampled 260 times in a year – this is the standardized number of business days per year. This "ftse" data was built as a regular time series; because a regular time series needs evenly-spaced intervals, the 260 divisions of a year don't exactly line up with common real-world divisions like days, weeks, or months, so we need to represent the time points with decimal dates.

6. Regular vs. irregular time series

In a regular time series, all observations are evenly-spaced, without missing values between observations. This is how base R handles time series, and can be cumbersome with real-world times, like data that only occurs on weekdays! Irregular time series – supported by the zoo package – do not have to be evenly-spaced. Values for observations can also be missing or NA. Because irregular time series do not require even spacing, we can use any date-time class, like numeric decimal date, Date, or POSIXct.

7. Let's practice!

Let's practice retrieving the temporal attributes of a time series object!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.