1

I am working with a data set that has two columns, one of which will have useful information. The one without information will have NA as its value. I would like this information to go into a third column together. An example of the data would be as below

 1 NA NA
 2 NC NA
 3 NA Alabama

What would be a method to have the third column produce:

  1 NA
  2 NC
  3 Alabama

I tried paste(), but this yields the data below: The NAs in this case also become characters that say "NA".

 1 NA NA
 2 NC NA
 3 NA Alabama

Any ideas as to how to achieve the 2nd table as opposed to the third, with the NA values retaining their NA status instead of being a character string?

Auresm
  • 139
  • 8

1 Answers1

2

We can use coalecse from dplyr

library(dplyr)
df1 %>%
   transmute(coln = coalecse(col1, col2))
akrun
  • 874,273
  • 37
  • 540
  • 662