title: Using plyr in R to count
body: <p>I am trying to compute summary statistics for a data file I have. I have seen several articles on similar topics but they didn't quite answer my questions. The data file contains sensitive material so I don't want to share it. But I will use the baseball data set in plyr to demonstrate what I'm trying to do. </p>
  
  <p>I am trying to compute a table of summary statistics, and one of the statistics requires making a count on unique elements of a factor variable. So if we use the baseball package for example, how would I go about finding how many teams each player had played for and attaching that to the rest of the dataset (the rest of the dataset being the other summary statistics I have computed on a per player basis)?</p>
  
  <pre><code>ddply(baseball, "id", summarise, total_games=sum(g),    
        still_active=ifelse(max(year) ==‌ 2007,"Yes","No"),
        number_teams=as.data.frame(
            with(baseball[!duplicated(baseball$te‌​am)],table(id))))
  </code></pre>
  
  <p>Above is an example, the very last parameter is the one I'm struggling with. How do I find the number of teams each player has been on? I have been trying to use  <code>as.data.frame(table())</code>, but have had no success.</p>