title: DDPLY Grouping Error
body: <p>I'm running a <code>ddply</code> function and keep getting an error.  </p>
  
  <p><strong>Structure of data.frame:</strong></p>
  
  <pre><code>str(visits.by.user)
  'data.frame':   80317 obs. of  5 variables:
   $ ClientID    : Factor w/ 147792 levels "50912733","50098716",..: 1 3 4 5 6 7 8 10 11 12 ...
   $ TotalVisits      : int  64 231 18 21 416 290 3 13 1 7 ...
   $ TotalDayVisits: int  8 141 0 4 240 155 0 0 0 0 ...
   $ TotalNightVisits: int  56 90 18 17 176 135 3 13 1 7 ...
   $ quintile         : Factor w/ 5 levels "0-20","20-40",..: 5 5 4 4 5 5 2 4 1 3 ...
  </code></pre>
  
  <p><em>Side note:</em>  I know how to create sample data for random numeric data - How do you apply a factor with 5 levels to build a representative sample?</p>
  
  <p><strong>ddply Code:</strong></p>
  
  <pre><code>summary.users &lt;- ddply(data = subset(visits.by.user, TotalVisits &gt; 0), 
                            .(quintile, TotalDayVisits, TotalNightVisits), 
                            summarize,
                            NumClients = length(ClientID))
  </code></pre>
  
  <p><strong>Error Message:</strong></p>
  
  <pre><code>Error in if (empty(.data)) return(.data) : 
   missing value where TRUE/FALSE needed
  </code></pre>
  
  <p>I thought that maybe <code>ddply</code> would require the variable I'm trying to group on to be a factor, so I tried a <code>as.factor</code> on the integer variables, but that didn't work.  </p>
  
  <p>Can anyone see where i'm going wrong?</p>
  
  <p>Edit:  Adding top part of <code>dput</code></p>
  
  <pre><code>structure(list(ClientID = structure(c(1L, 2L, 3L, 4L, 5L, 6L), .Label = c("50912733", "60098716", "50087112", "94752212", "78217771", "12884545"), class = "factor"),TotalVisits = c(80L, 92L, 103L, 18L, 182L, 136L), TotalDayVisits = c(56L, 90L, 18L, 17L, 176L, 135L), TotalNightVisits = c(24L, 2L, 85L, 1L, 6L, 1L), quintile = structure(c(5L, 5L, 4L, 4L, 5L, 5L), .Label = c("0-20", "20-40", "40-60", "60-80", "80-100"), class = "factor")), .Names = c("ClientID", "TotalVisits", "TotalDayVisits", "TotalNightVisits", "quintile"), row.names = c(NA,6L), class = "data.frame")
  </code></pre>