title: R CUT Data Table
body: <p>I have the following problem when doing a cut on a data.table.
  I don't know why it doesn't do the filter by "prod" correctly.
  If I run the cut on the outside, as seen below, it does the cut correctly but not inside the data table.
  Do you know why and how I can fix it?
  Thank you    </p>
  
  <pre><code>library(data.table)
      db&lt;-data.frame(count=c(331948, 334999, 321000, 305000, 324100, 310000, 305000, 325000, 305000, 329999, 315000,531948, 534999, 521000, 505000, 524100, 510000, 505000, 525000, 505000, 529999, 515000), prod=c("a","a","a","a","a","a","a","a","a","a","a","b","b","b","b","b","b","b","b","b","b","b"))
  
  head(db)
  
      count prod
  1  331948    a
  2  334999    a
  3  321000    a
  4  305000    a
  5  324100    a
  6  310000    a
  
  setDT(db)[ , id := cut(count,8,digits=1,dig.lab = 7), by = prod]
  
      count prod                  id
  1: 331948    a   (531249.1,535029]
  2: 334999    a   (531249.1,535029]
  3: 321000    a (519999.5,523749.4]
  4: 305000    a   (504970,508749.9]
  5: 324100    a (523749.4,527499.2]
  6: 310000    a (508749.9,512499.8]
  
  table(db[db$prod=='a',]$id)
  
   (504970,508749.9] (508749.9,512499.8] (512499.8,516249.6] (516249.6,519999.5] (519999.5,523749.4] (523749.4,527499.2] (527499.2,531249.1]   (531249.1,535029] 
                    3                   1                   1                   0                   1                   2                   1                   2 
  
  table(cut(db[db$prod=='a',]$count,8,digits=1,dig.lab = 7))
  
  (304970,308749.9] (308749.9,312499.8] (312499.8,316249.6] (316249.6,319999.5] (319999.5,323749.4] (323749.4,327499.2] (327499.2,331249.1]   (331249.1,335029] 
                    3                   1                   1                   0                   1                   2                   1                   2 
  </code></pre>