I have a very annoying task of collecting melted data into single cells. I feel like it's very hard to explain what I need in words so here's an example:
example input:
**ID, TAG**
id1, tag1
id1, tag2
id1, tag3
id2, tag1
id2, tag3
id3, tag2
id3, tag4
output:
**ID, TAGS**
id1, tag1 | tag2 | tag3
id2, tag1 | tag3
id3, tag2 | tag4
I hope that makes sense. So basically the tags collected into cells and separated by bars.
Thanks
EDIT:
df <- structure(list(ID = c("id1", "id1", "id1", "id2", "id2", "id3",
"id3"), TAG = c("tag1", "tag2", "tag3", "tag1", "tag3", "tag2",
"tag4")), row.names = c(NA, -7L), class = c("tbl_df", "tbl",
"data.frame"))
EDIT:
For some reason
df %>%
group_by(TAG) %>%
summarise(tags = paste(TAG, collapse = ", "))
did not work
This worked for me:
df %>%
ddply(.(ID), summarise, TAGS=paste(TAG, collapse=" | "))