title: R: Variable lengths differ
body: <p>I'm trying to create a linear model based off a time series analysis such as the following:</p>
  <p>Model 1 = novice_crash ~ time + grad + time.after + month</p>
  <p>I have the following code that creates the variables in question above:</p>
  <pre><code>grad&lt;- c(replicate(66,0),replicate(30,1))
  grad&lt;- ts(grad, start=c(2002,1), frequency=12)
  
  time&lt;- seq(1,96, by=1)
  time&lt;- ts(time,start=c(2002,1), frequency = 12)
  
  time.after&lt;- c(replicate(66,0),replicate(30,1))
  time.after&lt;- ts(time.after, start=c(2002,1), frequency = 12)
  
  #month&lt;- seasonaldummy(novice_crashes)
  month&lt;-time
  
  grad.lag1&lt;- lag(grad)
  
  time.after.lag1&lt;- lag(time.after)
  </code></pre>
  <p>'novice_crashes' is a ts object that comes from the following code (where 'crashes' is a csv file</p>
  <pre><code>novice&lt;- crash$novice_crash
  total&lt;- crash$total_crash
  novice_crashes&lt;-ts(novice, start = c(2002,12), end=c(2009,12), frequency = 12)
  </code></pre>
  <p>When I try to run this <code>model1&lt;- lm(novice_crashes ~ time + grad + time.after + month)</code> I get the following error:</p>
  <pre><code>Error in model.frame.default(formula = novice_crashes ~ time + grad + : variable lengths differ (found for 'time')
  </code></pre>
  <p>I have checked the lengths of time, grad, time.after and month (which are all 96 units long).</p>
  <p>The dataset <code>crash</code> had NA's present but I removed with</p>
  <pre><code>crash&lt;- na.omit(crash)
  </code></pre>
  <p>Im much more used to python so I may be missing something here...</p>