df <- data.frame("name" = c("jack", "william", "david", "john"),
"01-Jan-19" = c(NA,"A", NA,"A"),
"01-Feb-19" = c("A","A",NA,"A"),
"01-Mar-19" = c("S","A","A","A"),
"01-Apr-19" = c("A","A","A","S"),
"01-May-19" = c(NA,"A","A","A"),
"01-Jun-19" = c("A","S","A","S"),
"01-Jul-19" = c("A","S","A","S"),
"01-Aug-19" = c(NA,"S","A","A"),
"01-Sep-19" = c(NA,"S","A","S"),
"01-Oct-19" = c("S","S","A","S"),
"01-Nov-19" = c("S","S",NA,"S"),
"01-Dec-19" = c("S","S","S",NA),
"01-Jan-20" = c("S","M","A","M"),
"01-Feb-20" = c("M","M","M","M"))
For estimating the duration for each person between the first A to the last A, I was able to get that with the following piece of code:
But I want to find the periods in between the two As, and also how can I eliminate the period that is with other values (anything that is not A, e.g. S, NA)?