Forecast Hourly Partitioning Data and Plotting
<p>I am trying to forecast hourly sales based on past years of data, display the plot of the forecast with x axis SaleDateTime, and check the accuracy against a test set of dates.  I keep running in to errors.  </p>

<p>I tried using dput to generate a small sample of data but for some reason it still tries to output many more dates then I have in the subset sample data.</p>

<p>My data looks like this: SaleDateTime = "2015-01-02 23:00:00.000" and SaleCount = "1".</p>

<p>It looks like my main issue is with how I'm trying to partition the data into training and test sets.  </p>

<p>Also I would like to x axis on the plot to have the form "2015-03-01 23:00:00".  I'm pretty new to forecasting so all help is very much appreciated.</p>

<p>Code:</p>

<pre><code>library("forecast")
library("zoo")

SampleData &lt;- read.csv("SampleDataAll.csv")

Value&lt;-SampleData[,c("SaleDateTime","SaleCount")]

rDateTime&lt;-as.POSIXct(SampleData$SaleDateTime, format="%Y-%m-%d %H:%M:%S")

eventdata &lt;- zoo(Value, order.by = rDateTime)
timeseries &lt;- ts(eventdata$SaleCount, frequency=24)

##Partitioning data Training/Testing
ts1Train &lt;- window(timeseries,start="2011-08-01 00:00:00", end="2014-08-01 00:00:00")
</code></pre>

<p>Error:
Error in window.default(x, ...) : 'start' cannot be after 'end'
In addition: Warning message:
In window.default(x, ...) : 'end' value not changed</p>

<pre><code>ts1Test &lt;- window(timeseries,start="2014-08-01 01:00:00", end="2015-08-01 00:00:00")
</code></pre>

<p>Error in window.default(x, ...) : 'start' cannot be after 'end'
In addition: Warning message:
In window.default(x, ...) : 'end' value not changed</p>

<pre><code>fcast2&lt;-forecast(ts1Train,h=8764)
</code></pre>

<p>Error:
Error in forecast(ts1Train, h = 8764) : object 'ts1Train' not found</p>

<pre><code>plot(fcast2)

accuracy(fcast2,ts1Test)
</code></pre>

<p>Error:
Error in frequency(x) : object 'ts1Test' not found</p>

<p>UPDATE:</p>

<p>I made the changes below to how I partition the training and testing data as per the suggestion.  Now I'm getting the error message below when I try to run accuracy on the ts1Test data.</p>

<p>New Code:</p>

<pre><code>library("forecast")
library("zoo")

SampleData&lt;-SampleData

Value&lt;-SampleData[,c("SaleDateTime","SaleCount")]

rDateTime&lt;-as.POSIXct(SampleData$SaleDateTime, format="%Y-%m-%d %H:%M:%S")

eventdata &lt;- zoo(Value, order.by = rDateTime)

##Partitioning data Training/Testing
ts1SampleTrain&lt;-eventdata[1:2000,]
ts1Train&lt;-ts(ts1SampleTrain$SaleCount, frequency=24)


ts1SampleTest&lt;-eventdata[2001:28567,]
ts1Test&lt;-ts(ts1SampleTest$SaleCount, frequency=24)



#Training Model
fcast2&lt;-forecast(ts1Train,h=8567)

plot(fcast2)

accuracy(fcast2,ts1Test)
</code></pre>

<p>New Error:</p>

<p>Error in <code>-.default</code>(xx, ff[1:n]) : 
  non-numeric argument to binary operator</p>