Group by columns and summarize a column into a list : <p>I have a dataframe like this: </p>

<pre><code>sample_df&lt;-data.frame(
   client=c('John', 'John','Mary','Mary'),
   date=c('2016-07-13','2016-07-13','2016-07-13','2016-07-13'),
   cluster=c('A','B','A','A'))

#sample data frame
   client date         cluster
1  John   2016-07-13    A 
2  John   2016-07-13    B 
3  Mary   2016-07-13    A 
4  Mary   2016-07-13    A             
</code></pre>

<p>I would like to transform it into different format, which will be like:</p>

<pre><code>#ideal data frame
   client date         cluster
1  John   2016-07-13    c('A,'B') 
2  Mary   2016-07-13    A 
</code></pre>

<p>For the 'cluster' column, it will be a list if some client is belong to different cluster on the same date.</p>

<p>I thought I can do it with dplyr package with commend as below</p>

<pre><code>library(dplyr)
ideal_df&lt;-sample %&gt;% 
    group_by(client, date) %&gt;% 
    summarize( #some anonymous function)
</code></pre>

<p>However, I don't know how to write the anonymous function in this situation. Is there a way to transform the data into the ideal format?</p>
