Using time series objects

In this recipe, we look at various features to create and plot time-series objects. We will consider data with single and multiple time series.

Getting ready

If you have not already downloaded the data files for this chapter, do it now and ensure that the files are in your R working directory.

How to do it...

  1. Read the data. The file has 100 rows and a single column named sales:
    > s <- read.csv("ts-example.csv")
  2. Convert the data to a simplistic time series object without any explicit notion of time:
    > s.ts <- ts(s)
    > class(s.ts)
    [1] "ts"
  3. Plot the time series:
    > plot(s.ts)
    How to do it...
  4. Create a proper time series object with time points:
    > s.ts.a ...

Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.