I have a dataframe like this:
sample_df<-data.frame(
client=c(\'John\', \'John\',\'Mary\',\'Mary\'),
date=c(\'2016-07-13\',\'2016-07-13\',\'2016-07
We can use toString
to concat the unique
elements in 'cluster' together after grouping by 'client'
r1 <- sample_df %>%
group_by(client, date) %>%
summarise(cluster = toString(unique(cluster)))
Or another option would be to create a list
column
r2 <- sample_df %>%
group_by(client, date) %>%
summarise(cluster = list(unique(cluster)))
which we can unnest
library(tidyr)
r2 %>%
ungroup %>%
unnest()