title: Fitting regression line to timeseries data in R
body: <p>I have a monthly data set <code>test</code> that when plotted, looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/Pf37T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Pf37T.png" alt="enter image description here"></a></p>
  
  <p>My objective is to fit a regression line to the data and create a forecast of future months (to start with, 6 months).  I have consulted <a href="https://www.otexts.org/fpp/4/8" rel="nofollow noreferrer">this reference</a> which implements the <code>forecast</code> package.  </p>
  
  <p>However, when I run <code>tslm()</code>,  I get the following errors:</p>
  
  <pre><code>tslm(test$Freq)
  Error in formula.default(object, env = baseenv()) : invalid formula
  </code></pre>
  
  <p>And also when I attempt to convert <code>test</code> to a timeseries object, I get another error. </p>
  
  <pre><code>as.Date(as.character(test$Month))
  Error in charToDate(x) : 
    character string is not in a standard unambiguous format
  </code></pre>
  
  <p>Any suggestions on how to properly implement the <code>tslm()</code> function on the given data set would be greatly appreciated.  Here is the data sample:</p>
  
  <pre><code>&gt; dput(test)
  structure(list(Month = structure(1:31, .Label = c("2014-11", 
  "2014-12", "2015-01", "2015-02", "2015-03", "2015-04", "2015-05", 
  "2015-06", "2015-07", "2015-08", "2015-09", "2015-10", "2015-11", 
  "2015-12", "2016-01", "2016-02", "2016-03", "2016-04", "2016-05", 
  "2016-06", "2016-07", "2016-08", "2016-09", "2016-10", "2016-11", 
  "2016-12", "2017-01", "2017-02", "2017-03", "2017-04", "2017-05"
  ), class = "factor"), Freq = c(3L, 15L, 863L, 1031L, 4242L, 11610L, 
  20605L, 21105L, 29533L, 27354L, 30573L, 24423L, 20216L, 13616L, 
  9674L, 10037L, 13959L, 18760L, 28121L, 34346L, 36099L, 35841L, 
  39318L, 30736L, 27517L, 12588L, 13599L, 14465L, 17142L, 26229L, 
  29484L)), .Names = c("Month", "Freq"), row.names = c(NA, -31L
  ), class = "data.frame")
  </code></pre>