title: Weird output length using for
body: <p>I want to have a test to see if my data makes sense, so I want to compare 2 columns of my dataset. It has to do with distances, so I compare Yn - Yn-1 to Xn - Xn-1.</p>
  
  <pre><code>x&lt;-c(1,2,3,0,2,0,5,8,2,10,2,0,1,0)
  CSx&lt;-cumsum(x)
  y&lt;-c(1,1.5,2,2,3,3,2,6,1,8,9,10,11,12)
  test1&lt;-as.data.frame(cbind(x, CSx, y))
  bla&lt;-NA
  for (n in 2:length(test1[,1])){
   j&lt;-test1[n,2]
   k&lt;-test1[n-1,2]
   l&lt;-test1[n,3]
   m&lt;-test1[n-1,3]
   ifelse((l-m)/(j-k)&gt;1, bla&lt;-append(bla, "WRONG!!!"), bla&lt;-append(bla, "ok"))
  }
  </code></pre>
  
  <p>I therefore expect to have <code>length(test1)</code> values, the first being <code>NA</code>, and then 13 calculated values, from 2 to 14 in these case. I only get 12:</p>
  
  <pre><code>&gt; length(2:length(test1[,1]))
  # [1] 13
  &gt; bla
  # [1] NA         "ok"       "ok"       "ok"       "ok"       "ok"      
  # [7] "ok"       "ok"       "ok"       "WRONG!!!" "ok"       "WRONG!!!"
  &gt; length(bla)
  # [1] 12
  </code></pre>
  
  <p>I guess there is a perfectly logical and simple reason for this, but I am utterly confused.</p>