title: Tallying the numbers into bins using hist function
body: <p>I want to tally the numbers in a vector into custom bins.
  Suppose my custom bins are: <code>[-Inf, -1), [-1, 0), [0, 1.5)</code> and <code>[1.5, Inf)</code>. 
  And the vector I want to classify is <code>c(.5, 2)</code>.   </p>
  
  <p>Basically what I want is the result of this:</p>
  
  <pre><code>hist(x = c(.5,2), breaks = c(-1000, -1, 0, 1.5, 1000), plot = FALSE)$count
  
  [1] 0 0 1 1
  </code></pre>
  
  <p>Clearly, this will give an error if the vector is out of boundaries:</p>
  
  <pre><code>hist(x = c(.5, 2, 1001), breaks = c(-1000, -1, 0, 1.5, 1000), plot = FALSE)$count
  
  Error in hist.default(x = c(0.5, 2, 1001), breaks = c(-1000, -1, 0, 1.5,  : 
    some 'x' not counted; maybe 'breaks' do not span range of 'x'
  </code></pre>
  
  <p>And the following code is surprisingly not working:</p>
  
  <pre><code>hist(x = c(.5,2), breaks = c(-Inf, -1, 0, 1.5, Inf), plot = FALSE)$count
  
  [1] 2 0 0 0
  </code></pre>
  
  <p>Possibly I can use <code>findInterval</code> function, but I don't want to use it because the code will be longer and there is a possibility of empty bins and I want to know them.</p>
  
  <p>Any ideas?</p>