R: Making pivot table with dplyr or reshape2 package
<p>I am trying to make simple pivot table in R using <code>dplyr</code> or <code>reshape2</code> packages as my dataset is too large and R goes out of memory with <code>sqldf</code>. The two columns of my dataset that I want to make a pivot table out of is <code>"Product"</code> and <code>"Cust_Id"</code>. I want to count the number of customer per product. And this is what I got.</p>

<pre><code>library(reshape2)
mydata&lt;-read.table("Book1.txt",header=TRUE,fill=TRUE)
mydata.m&lt;-melt(mydata,id=c("Product"),measured=c(Cust_Id))
mydata.d&lt;-dcast(mydata.m,Product~variable,count)
</code></pre>

<p>It returns</p>

<pre><code>Error in UseMethod("group_by_"):
no applicable method for 'group_by_' applied to an object of class "c('integer','numeric')"
</code></pre>

<p>I have also tried <code>dplyr</code> with below code(not sure about the last step though as I did it on the other laptop)</p>

<pre><code>library(dplyr)
mydata.df&lt;-tbl_df(mydata)
summarize(mydata.df,Product,Cust_Id=n())  
</code></pre>

<p>I got no error message but a lot of values seems to be missing in the output.
I really appreciate your input. Thanks in advance.</p>