title: Calculating number of values less than x by row of data frame
body: <p>I have searched the forums and the web high and low for the last two days, and broken down my script to try and find the issue, but for some reason, I can't get this to work properly beyond the first row:</p>
  
  <pre><code>numbers &lt;- mtcars[1:6,]
  
  nnn &lt;- c(1:(nrow(numbers)))
  
  for (i in nnn){
    ly &lt;- numbers[i,]
    numbers[i,12]&lt;- sum(abs(ly) &lt; 5e0)
  }
  </code></pre>
  
  <p>This returns:</p>
  
  <pre><code>&gt; numbers
                     mpg cyl disp  hp drat    wt  qsec vs am gear carb V12
  Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4   6
  Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4  NA
  Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1  NA
  Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1  NA
  Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2  NA
  Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1  NA
  </code></pre>
  
  <p>As you can see, when i is 1, ly is the mazda rx4 row, and it performs</p>
  
  <pre><code>sum(abs(ly) &lt; 5e0)
  </code></pre>
  
  <p>correctly, placing the value 6 in a new 12th column. However, beyond that, even though I've determined that it is looping through i correctly, and returning ly correctly for each iteration of i, its not calculating the sum part for rows 2:5</p>
  
  <p>Its probably really obvious to most what I am doing wrong here, but for the life of me I can't pick it. I'm new to R and programming, self taught pretty much, and I've written quite a few successul for loops and scripts so far in the last few weeks, but this has me dumfounded. Someone else in our research group who uses Matlab went through it with me, the problem down the same as I did, and she couldn't figure out why it wouldn't work either.</p>
  
  <p>I've used mtcars so far just to test the loop and so that its easily accessible to those on the forum. Once I know it works, I'll translate it for my dataset (which is quite large).</p>