This may be an easy one but I could not find a solution. I have a df of strings, for example:
data <- data.frame(x1 = c("abc", "", "de"),
x2 = c("fghi", "j", "kl"),
x3 = c("m", "", ""))
> data
x1 x2 x3
1 abc de
2 fghi j kl
3 m
I want to concatenate each row into a single string, so that the output only has one column:
> data
x1
1 abc de
2 fghi j kl
3 m
I tried
apply(data, 2, paste)
but it doesn't work, and neither does any variation of stringr::str_c. any thoughts?