4
Hello,
I have a database in which I used tidyr::spread which resulted in information spread across several lines. I would like to join the different lines in one. Example:
df <- data.frame(obs = c(1,1,1,2),
msgA = c("A", NA, NA, "A" ),
msgB = c(NA,"B",NA, NA),
msgC = c(NA,NA,"C", NA))
#O que eu tentei:
library(dplyr)
df %>%
group_by(obs) %>%
mutate(msg = paste(msgA, msgB, msgC, sep=", ")) %>%
select(-c(2:4))
# Resultado que eu queria:
#
# > df
# obs msg
# 1 A, B, C
# 2 A
Thanks for your help!