How to do it...

Let's move on to the data processing part:

  1. First, we check the datatype of the Sales column in our data:
class(data$Sales)

Note that, in the data, the Sales column is of the factor datatype. We need to make this a numeric datatype in order to use it in our analysis:

data$Sales <- as.numeric(as.character(data$Sales))class(data$Sales)

Now, the class of the Sales column has been changed into a numeric datatype.

  1. To implement a time series forecast, we need to convert the data into stationary data. We can do this using the diff() function, which will calculate the iterated difference. We pass the value of the argument differences as 1 since we want the differencing to have a lag of 1:
data_differenced = diff(data$Sales, ...

Get Deep Learning with R Cookbook 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.