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
  • 482,603
  • 120
  • 884
  • 1,141
ranaz
  • 107
  • 10

1 Answers1

2

We can use coalesce

library(tidyverse)
df1 %>%
     mutate(EventDate = coalesce(SDate, CDate))
akrun
  • 674,427
  • 24
  • 381
  • 486