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

Performing preliminary analyses on time series data

Before creating proper time series objects, we may want to do some preliminary analyses. This recipe shows you how.

Getting ready

The base R package provides all the necessary functionality. If you have not already downloaded the data files for this chapter, please do it now and ensure that they are located in your R working directory.

How to do it...

  1. Read the file. We will use a data file that has the share prices of Walmart (downloaded from Yahoo Finance) between March 11, 1999 and January 15, 2015:
    > wm <- read.csv("walmart.csv")
  2. View the data as a line chart:
    > plot(wm$Adj.Close, type = "l")

    The data can be viewed as a line chart as follows:

  3. Compute and plot daily price movements:
    > d <- diff(wm$Adj.Close) ...

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