title: Using dplyr for frequency counts of interactions, must include zero counts
body: <p>My question involves writing code using the <strong>dplyr</strong> package in R</p>
  
  <p>I have a relatively large dataframe (approx 5 million rows) with 2 columns: the first with an individual identifier (<code>id</code>), and a second with a date (<code>date</code>).  At present, each row indicates the occurrence of an action (taken by the individual in the id column) on the date in the date column.  There are about 300,000 unique individuals, and about 2600 unique dates.  For example, the beginning of the data look like this:</p>
  
  <pre><code>    id         date
      John12     2006-08-03
      Tom2993    2008-10-11
      Lisa825    2009-07-03
      Tom2993    2008-06-12
      Andrew13   2007-09-11
  </code></pre>
  
  <p>I'd like to reshape the data so that I have a row for every possible <code>id</code> x <code>date</code> pair, with an additional column which counts the total number of events that occurred (perhaps taking the value 0) for the listed individual on the given date.  </p>
  
  <p>I've had some success with the <strong>dplyr</strong> package, which I've used to tabulate the id x date counts which are observed in the data.  </p>
  
  <p>Here's the code I've used to tabulate <code>id</code> x <code>date</code> counts so far: (my dataframe is called <em>df</em>)</p>
  
  <pre><code>reduced = df %.% 
    group_by(id, date) %.%
    summarize(length(date))
  </code></pre>
  
  <p>My problem is that (as I said above) I'd like to have a dataset that also includes 0s for id x date pairs that don't have any associated actions.  For example, if there's no observed action for John12 on 2007-10-10, I'd like the output to return a row for that <code>id</code> x <code>date</code> pair, with a count of 0.  </p>
  
  <p>I considered creating the frame above, then mergine with an empty frame, but I'm convinced there must be a simpler solution.  Any suggestions much appreciated!  </p>