I have the following data frame with 3 columns
category <- c("A", "A", "A", "B","B")
id <- c(1,1,2,3,3)
text <- c("abc", "def", "ghi", "jkl", "pqr")
df <- data.frame(category,id,text)
> df
category id text
1 A 1 abc
2 A 1 def
3 A 2 ghi
4 B 3 jkl
5 B 3 pqr
I want to concatenate the text per id per group
My output needs to be like:
A 1 "abc def"
A 2 "ghi"
B 3 "jkl pqr"
I tried using
library(stringr)
str_c(df[,3], collapse = NULL)
But my output is not correct, also how can I get this per id per group