Get startedGet started for free

Basic time series objects

1. Basic time series objects

A time series is more than a vector of numbers, it also includes the time indices for each observation.

2. Building ts() objects - I

Given a vector of numbers you can apply the ts() function to create a time series object. Such objects are of the `ts` class. They represent data that is at least approximately evenly spaced over time. Consider the following data_vector which has just eight observations. To make this vector a time series object you apply the ts() function When you plot the result using the plot() function the time index and label is automatically added to the horizontal axis. By default, R uses a simple observation index starting from 1 as the time index.

3. Building ts() objects - II

If you want the time series to start in the year 2001 with 1 observation per year you should apply the ts() function with the additional arguments start = 2001 and frequency = 1 as shown. Now when you plot the result you can see an updated time axis, running from 2001 through 2008.

4. Using is.ts()

You can use the function is.ts() to check whether a given object is a time series. As you can see, it reports FALSE for the data_vector and true for the time_series that were just created.

5. Why ts() objects?

Remember: why do you want to create and work with time series objects of the ts class? There are many methods and functions available for utilizing time series attributes, especially for plotting and for accessing time index information. And as we will see in later chapters, for estimating time series models and for making forecasts.

6. Let's practice!

Now let's practice with some exercises!