title: Excluding rows with NAs in column-wise calculations
body: <p>I have the below function:</p>
  
  <pre><code>colNames = c(1,4)
  myfun = function(a,b){
    test$result = 0.0
    for (i in colNames)
    { 
      test$result = test$result + (test[,i] * exp(-a*test[,i+1]) * exp(b*test[,i+2]))
    }
    return(test$result)
  }
  </code></pre>
  
  <p>I am basically trying to multiply 3 columns in a sequence (by performing exp operation on i+1 and i+2th columns and multiplying them with col i) and adding their result to a similar operation done to the next 3 columns.</p>
  
  <p>However, I have several null values and whenever I encounter a row in test[,i] with a null value, I want to exclude it from the calculation and perform the next loop.</p>
  
  <p>I mean rows with null values in test[,i] should not be used in the calculation of test$result. Is there anyway to do this?</p>
  
  <p>Sample data:</p>
  
  <pre><code>2   1708.637715 21.30199589 1   408.4464296 19.8614872
  1   1708.637715 21.30199589 1   408.4464296 19.8614872
  2   1708.637715 21.30199589 1   408.4464296 19.8614872
  1   1708.637715 21.30199589 1   408.4464296 19.8614872
  6   1708.637715 21.30199589 NA  408.4464296 19.8614872
  0   1708.637715 21.30199589 NA  408.4464296 19.8614872
  </code></pre>
  
  <p>My first iteration should run normally, but in the next iteration only columns 1 to 4 have to be used in the addition</p>
  
  <p>Please help</p>