I am attempting to take the minimum date in a sequence of dates that is after all NAs before that sequence, and the only thing after that sequence is either NAs, or, that date sequence is the last columns.
This is better explained through example:
sample <- data.frame(subject = c("A","B","C"),Date1 = c("1-2-19","1-2-19",NA),Date2 = c("1-3-19",NA,"1-3-19"),Date3 = c("1-4-19","1-4-19",NA)
,Date4 = c(NA,"1-5-19",NA),Date5 = c("1-6-19",NA,NA),Date6 = c("1-7-19",NA,"1-7-19"))
Ouput:
subject Date1 Date2 Date3 Date4 Date5 Date6
1 A 1-2-19 1-3-19 1-4-19 <NA> 1-6-19 1-7-19
2 B 1-2-19 <NA> 1-4-19 1-5-19 <NA> <NA>
3 C <NA> 1-3-19 <NA> <NA> <NA> 1-7-19
The hoped for result is to have an additional colum called Minimum_Date, where the expected result for each row is entered.
So Subject A would return '1-6-19'
Subject B would return '1-4-19'
Subject C would return '1-7-19'