O'Reilly logo

R Data Analysis Cookbook by Shanthi Viswanathan, Viswa Viswanathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required