title: if statement in R. Error argument is of length zero
body: <p>This is my code </p>
  
  <pre><code>for (i in 101:length(temp[,6]))
  { 
    if (   temp[i-1,5]&lt; temp[i,5]  ) 
    print(temp[i,])
  
  }
  </code></pre>
  
  <p>temp is my data </p>
  
  <pre><code>     000001.SZ.Open 000001.SZ.High 000001.SZ.Low 000001.SZ.Close 000001.SZ.Volume 000001.SZ.Adjusted
  2016-01-01          11.99          11.99         11.99           11.99                0            9.81595
  2016-01-04          12.00          12.03         11.23           11.33         67619700            9.27563
  2016-01-05          11.27          11.57         11.15           11.40         79592300            9.33293
  2016-01-06          11.42          11.56         11.39           11.53         61884700            9.43936
  2016-01-07          11.41          11.41         10.91           10.94         20971300            8.95634
  2016-01-08          11.21          11.29         10.90           11.12         89703300            9.10370
  </code></pre>
  
  <p>looks like this. I checked the data with code  <code>is.numeric</code> </p>
  
  <pre><code>is.numeric(temp)
  [1] TRUE
  </code></pre>
  
  <p>and <code>is.null</code></p>
  
  <pre><code>is.null(temp)
  [1] FALSE
  </code></pre>
  
  <p>Therefore all the value in "temp" has meaning and able to calculate.</p>
  
  <p>I got the result </p>
  
  <pre><code>Error in if (temp[i - 1, 5] &lt; temp[i, 5]) print(temp[i, ]) : 
    argument is of length zero 
  </code></pre>
  
  <p>Please tell me where is the problem with this code.</p>