I am trying to paste 2 text columns together. The problem is that some of the values in each column are NA and if that is the case, I don't want the NA as part of my pasted string. Here is an example of what I mean
some data:
dat <- data.frame("col1" = c("stuff", "stuff", "stuff", NA, NA),
"col2" = c("things", NA, "things", "things", NA))
dat
col1 col2
1 stuff things
2 stuff <NA>
3 stuff things
4 <NA> things
5 <NA> <NA>
This is what I need:
col1 col2 col3
1 stuff things stuff; things
2 stuff <NA> stuff
3 stuff things stuff; things
4 <NA> things things
5 <NA> <NA> <NA>
I can use paste() and then clean up the mess with gsub() but I was looking for a better one-liner.
Thanks