I Have below mentioned dataframe in R:
Unique_ID D_1 ST_1 D_2 ST_2 D_3 ST_3
JJ-123 2018-04-01 No Range 2018-03-12 50-80 2018-02-01 10-30
JJ-113 2018-04-01 50-80 2018-03-05 50-80 2018-02-01 10-30
JJ-457 2018-04-03 10-30 2018-03-12 1-5 2018-02-01 No Range
JJ-879 2018-04-01 No Range 2018-03-12 50-80 2018-02-01 50-80
Note: For the sake of simplicity i have mentioned only three ST_
value though in original dataframe I have column till ST_38
.
Dput:
structure(list(Unique_ID = c("JJ-123", "JJ-113", "JJ-457", "JJ-879"
), D_1 = c("01/04/2018", "01/04/2018", "03/04/2018", "01/04/2018"
), ST_1 = c("No Range", "50-80", "10-30", "No Range"), D_2 = c("12/03/2018",
"05/03/2018", "12/03/2018", "12/03/2018"), ST_2 = c("50-80",
"50-80", "1-5", "50-80"), D_3 = c("01/02/2018", "01/02/2018",
"01/02/2018", "01/02/2018"), ST_3 = c("10-30", "10-30", "No Range",
"50-80")), class = "data.frame", row.names = c(NA, -4L))
Using above dataframe I want to get oldest date when ST_
value change first time to 10-30
and 50-80
.
Output:
Unique_ID 10-30 50-80
JJ-123 2018-02-01 2018-03-12
JJ-113 2018-02-01 2018-03-05
JJ-457 2018-04-03 NA
JJ-879 NA 2018-02-01