title: How to count number of observations based on another variable values that are divided by ranges
body: <p>I would like to count number of observations based on another variable values that are divided by ranges. I was able to group the first variable (birds) and I was able to count its number of observations,however when I tried to get the number of observations for the second variable I got wrong answers as I show below.How can I overcome this issue?</p>
  
  <p>Here Is my data frame sample:</p>
  
  <pre><code>dat &lt;- read.table(text = "  birds    wolfs     snakes
                             2        9         7
                             90       8         4
                             90       2         8
                             100      2         3
                             100      8         3
                             660      1         2
                             660      7         1
                             660      1         5
                             500      9         7
                             30       8         7
                             40       2         7
                             10       2         3
                             70       6         3
                             60       1         1
                             60       3         9
                             60       1         1   ",header = TRUE)
  </code></pre>
  
  <p>I ran this line of code to get the groups:</p>
  
  <pre><code>dat$birdsrange &lt;- cut(dat$birds, breaks=seq(0, 1000, 25))  
  </code></pre>
  
  <p>Than I added two code lines:</p>
  
  <pre><code>dat$mbirds &lt;- with(dat, ave(birds, birdsrange, FUN=length))
  dat$mwolfs &lt;- with(dat, ave(wolfs, birdsrange, FUN=length))
  </code></pre>
  
  <p>So I got this output:</p>
  
  <pre><code>   birds wolfs snakes birdsrange mbirds mwolfs
  1      2     9      7     (0,25]      2      2
  2     90     8      4   (75,100]      4      4
  3     90     2      8   (75,100]      4      4
  4    100     2      3   (75,100]      4      4
  5    100     8      3   (75,100]      4      4
  6    660     1      2  (650,675]      3      3
  7    660     7      1  (650,675]      3      3
  8    660     1      5  (650,675]      3      3
  9    500     9      7  (475,500]      1      1
  10    30     8      7    (25,50]      2      2
  11    40     2      7    (25,50]      2      2
  12    10     2      3     (0,25]      2      2
  13    70     6      3    (50,75]      4      4
  14    60     1      1    (50,75]      4      4
  15    60     3      9    (50,75]      4      4
  16    60     1      1    (50,75]      4      4
  </code></pre>
  
  <p>The "mbirds" count is good however the "mwolfs" is bad as I expected to get 16 observation for the group: (0,25] and "0" for the other groups.How can I solve the problem?
  the desired outcome should be:</p>
  
  <pre><code>range mbirds mwolfs
  (0,25]  2      16
  (25,50] 2      0
  (50,75] 4      0
  </code></pre>
  
  <p>...</p>