I have this code and I want to join them by ID
df <- tibble(id = c("a","a","c"),
b = c("foo", "bar", "foo"),
c = c("x", "y", "z"))
df
# A tibble: 3 x 3
id b c
<chr> <chr> <chr>
1 a foo x
2 a bar y
3 c foo z
Expected Output:
id b c
<chr> <chr> <chr>
1 a foo bar x y
3 c foo z
I have tried this code below but it only returns me a character vector. I think this one does not work if value in group_by
is character/string
.
df %>% group_by(id) %>%
summarize(new = paste(b, collapse = " "),
new2 = paste(c, collapse = " "))