1

I am trying to write a code that create a new column to combine two rows together. The idea is to add the row when there is NA.

The new column will be the "EventDate

Here is a sample data frame:

Id    SDate         CDate                EventDate
101   2013-03-27    NA                   2013-03-27
101   2013-05-09    NA                   2013-05-09
101   NA            2013-05-30           2013-05-30
101   NA            2013-07-26           2013-07-26
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
ranaz
  • 97
  • 1
  • 10

1 Answers1

2

We can use coalesce

library(tidyverse)
df1 %>%
     mutate(EventDate = coalesce(SDate, CDate))
akrun
  • 874,273
  • 37
  • 540
  • 662