title: Large raster frequency table / counts
body: <p>I try to calculate the frequency/count of pixel values of a raster in R using freq().
  Create two example rasters for comparison:</p>
  
  <pre><code>library(raster)
  RastSmall &lt;- raster(nrow=70, ncol=70) 
  RastBig   &lt;- raster(nrow=7000, ncol=7000) 
  set.seed(0)
  RastSmall[] &lt;- round(runif(1:ncell(r_hr), 1, 5))
  RastBig[] &lt;- round(runif(1:ncell(r_hr), 1, 5))
  </code></pre>
  
  <p>Get the pixel count using freq()</p>
  
  <pre><code>freq(RastSmall)
  value    count
  [1,]     1  6540000
  [2,]     2 12150000
  [3,]     3 12140000
  [4,]     4 11720000
  [5,]     5  6450000  
  </code></pre>
  
  <p>However, it is a fairly large file and takes extremely long, i.e. up to hours. Is there a faster way in R? 
  Here the speed difference for a small and a large raster:</p>
  
  <pre><code>system.time(freq(RastSmall))
    user  system elapsed 
    0.008   0.000   0.004 
  system.time(freq(RastBig))
    user  system elapsed 
    40.484   0.964  41.445 
  </code></pre>
  
  <p>Is there a way to speed this up? Alternatively can this be done in the command line using something like gdal tools?</p>