title: Get counts for every factor in one column of data.table broken out by two other columns
body: <p>I have a <code>data.table</code> containing a column, <code>DT$Locale</code></p>
  
  <p>that has the following entries:</p>
  
  <pre><code>DT[,unique(Locale)]
  
  downstream                upstream                  intergenic                intron                    intron,nc                 regulatory                synonymous               
  non_coding_exon,nc        5_prime_UTR               splice,5_prime_UTR        splice,intron             missense                  3_prime_UTR               splice,intron,nc         
  splice,synonymous         splice_donor              synonymous,NMD            mature_miRNA              splice_donor,nc           splice_acceptor           3_prime_UTR,NMD          
  stop_gained               missense,NMD              5_prime_UTR,NMD           intron,NMD                splice,intron,NMD         splice,non_coding_exon,nc missense,splice          
  splice_acceptor,nc        coding_sequence,NMD       missense,splice,NMD       stop_lost                 initiator_codon           splice_acceptor,NMD
  </code></pre>
  
  <p>I have two other columns as well, having the following formats:</p>
  
  <pre><code>DT[,unique(Cohort)]
  [1] CEU   Lupus RA    YRI  RALoci
  
  DT[,unique(Locus)]
  
   [1] 1.110927656.111927656  1.194335780.195335780  1.217775877.218775877  1.236880267.237880267  1.85471701.86471701    10.52963302.53963302   10.6118896.7118896    
   [8] 10.74879027.75879027   11.20046869.21046869   12.37676238.38676238   12.38077040.39077040   13.92438484.93438484   14.47539055.48539055   14.89244697.90244697  
  [15] 14.98090299.99090299   14.98556636.99556636   15.101213744.102213744 15.47426024.48426024   16.13885034.14885034   16.27399400.28399400   16.48056833.49056833  
  [22] 16.5898498.6898498     16.63172805.64172805   16.76469520.77469520   16.86513832.87513832   17.4148334.5148334     18.4824309.5824309     18.54958827.55958827  
  [29] 2.146859650.147859650  2.229978358.230978358  2.86605444.87605444    20.19570642.20570642   22.39592645.40592645   3.41789975.42789975    3.7782962.8782962     
  [36] 3.85190848.86190848    4.141037599.142037599  4.29959034.30959034    5.128060465.129060465  5.65898794.66898794    5.7513893.8513893      6.56405042.57405042   
  [43] 7.124946062.125946062  8.18012618.19012618    9.28933416.29933416    9.87628311.88628311   
  </code></pre>
  
  <p>I wish to get a count of the type of each entry in <code>DT$Locale</code> for each combination of <code>DT$Cohort</code> and <code>DT$Locus</code>.</p>
  
  <p>It seemed to me the that libary <code>data.table</code> represented an effective way to do this, so I tried things like:</p>
  
  <p><code>DT[,sum(unique(Locale)),by="Locus,Cohort"]</code>, but this of returns an error - it seems to me there is likely an easy way to do this using lapply, but I have not hit on the correct syntax yet, can anyone offer a solution? </p>
  
  <p>Note: in response to posts:</p>
  
  <pre><code>RALociDT[,list(count=length(unique(Locale3))),by="Locus,Cohort"]
                       Locus Cohort count
    1: 1.110927656.111927656    CEU    14
    2: 1.110927656.111927656  Lupus    15
    3: 1.110927656.111927656     RA    14
    4: 1.110927656.111927656    YRI    13
    5: 1.194335780.195335780    CEU     4
   ---                                   
  180:   9.28933416.29933416    YRI     4
  181:   9.87628311.88628311    CEU    11
  182:   9.87628311.88628311  Lupus    10
  183:   9.87628311.88628311     RA     9
  184:   9.87628311.88628311    YRI    11
  </code></pre>
  
  <p>Returns the number of items in the list that appear, not the count of how many times each one that does appear occurs (by Locus and Cohort).</p>