I have a data frame df
that looks like below
ID value
123 6
123 5
123 4
124 3
124 8
137 9
140 12
154 9
154 8
167 10
I need to group them by comma
with respective ids and want results like below
ID value
123 6,5,4
124 3,8
137 9
140 12
154 9,8
167 10
I have tried the below code
library(dplyr)
df %>% group_by(ID) %>% summarise(val=paste(Value, collapse=","))
But results like this with a single row and single column
val
6,5,4,3,8,9,12,9,8,10
kindly help me out
Thanks in advance