woman contemplating computer
PHOTO: Valeriy Khan

R programming — along with another language, Python — have become vital tools for applying statistical analysis to online sales, digital campaign results or operational activity that supports a marketing plan or business decision.

But there are a number of ways to examine data in R, enough to cause analysis paralysis in marketers figuring out where to start. If you are a marketer suffering from such confusion, examining a time series of operational data is a good place to start.   

Related Article: How Marketers Can Plan Data Mining With R Programming

Why Time Series Data?

You probably have seen time series data in analytics solutions before. Google and Adobe display them as a default in most reports, and they pop up in other solutions as well. But most solutions graphics are not really designed for statistical analysis that can reveal details influential to a business decision. 

For example, you certainly can compare referral traffic sources to a website in the reporting of a solution. But suppose you needed to know if a growing trend was sustainable. The slope of a trendline may not be immediately clear, and you may be uncertain that spikes are an indicator of a changing behavior or just noise. This is where R comes in. It has functions that can help answer those questions. 

How to Get Started With Time Series Data in R

To start, you can use typical analytics metrics like visits or time in session, or data from sales or operations. Download and insert whichever data you choose to work with as a csv file or import with an API.   

Next, place the data into a times series object. For those who have not written code before: an object is just a general definition for a container to hold a value, just like a variable in algebra (e.g., x = 8 when 10 = x + 2). Object-oriented languages use containers all the time. In this instance the time series object is a data frame, a type of object in R that holds a matrix of data. You can then add functions to analyze the data. 

Here is a time series example, using a sample dataset called AirPassengers with a function called decompose. The AirPassengers dataset is a sample representing monthly totals of international airline passengers between 1949 and 1960 (most libraries in R provide a sample dataset for you to test ideas). The decompose function separates a time series dataset into three components of a data trend so you can view the data more clearly:

  1. Trend: A smoothed-out version of the data, showing an overall upward or downward trendline.
  2. Seasonal: A visual of spikes that represent the seasonality over a given time series. The graph displays the size of the spike and the frequency of the cycle. 
  3. Random: The “noise” in the data.

These components can then be graphed to review the data and decide whether an upward trend or downtrend is really apparent.

example of time series graph

Related Article: Here's Why Every Marketer Needs R Programming

Uncover Trends or Future Direction With Time Series

Analysis like this can help your organization determine if a time series is representing seasonal trends that potentially may repeat. If the data in the time series represents product sales, website visits, or another element in your business, the information can provide ideas on how that data fits in an advanced analysis like a predictive model, or trigger further management discussion about underlying assumptions supporting the trends.

In fact there’s another protocol in R called change point detection. This is meant to note where trends changes when the data has a lot of variability. There is also a library that allows users to test for the change point detection.

Practicing a time series in R will help you appreciate a statistical view of your sales and marketing data, allowing you to get ready for more complex analysis that is sure to come your way.