title: R: Applying function to specific rows only
body: <p>I'm trying to apply a function only to certain rows which meet my conditions. I've seen from other threads that I should use the "apply" function, but I can't seem to get it to work.<br>
  Here is what I have so far:  </p>
  
  <pre><code>a = which(decisionMatrix[,1]&gt;0 &amp; decisionMatrix[,4] &lt; decisionMatrix[,5] &amp;
            tail(ratios,1)&gt;decisionMatrix[4])
  </code></pre>
  
  <p>Which gives me the numbers of the rows which meet my conditions.  </p>
  
  <p>I then use:</p>
  
  <pre><code>apply(decisionMatrix[10],a,decisionMatrix[,1]/decisionMatrix[,5])
  </code></pre>
  
  <p>What I'm trying to do here is say "for each row that meets the above conditions, take the first column in that row and divide it by the fifth column in that row and store the result in the 10th column of that row"  </p>
  
  <p>Would anyone be able to give me some advice?  </p>