title: R Counting duplicate values and adding them to separate vectors
body: <pre><code>x &lt;- c(1,1,1,2,3,3,4,4,4,5,6,6,6,6,6,7,7,8,8,8,8)
  y &lt;- c('A','A','C','A','B','B','A','C','C','B','A','A','C','C','B','A','C','A','A','A','B')
  X &lt;- data.frame(x,y)
  </code></pre>
  
  <p>Above I have a data frame where I want to identify the duplicates in vector x, while counting the number of duplicate instances for both (x,y)....
   For example I have found that ddply and this post here is similar to what I am looking for (<a href="https://stackoverflow.com/questions/18201074/find-how-many-times-duplicated-rows-repeat-in-r-data-frame">Find how many times duplicated rows repeat in R data frame</a>).</p>
  
  <pre><code>library(ddply)
  ddply(X,.(x,y), nrow)
  </code></pre>
  
  <p>This counts the number of instances 1 - A occurs which is 2 times...  However I am looking for R to return the unique identifier in vector x with the counted number of times that x matches in column y (getting rid of vector y if necessary), like below..</p>
  
  <pre><code>x  A  B  C
  1  2  0  1
  2  1  0  0
  3  0  2  0
  4  1  0  2
  5  0  1  0
  6  2  1  2 
  </code></pre>
  
  <p>Any help will be appreciated, thanks</p>