mardi 16 janvier 2018

R keeps date counting by status

I am new in R, I have a data frame contain start_date, day difference and status, what I want to do is to use Sys.Date() minus start_date to check the days difference when the status is fail, and when the status goes to pass the date counting will be stopped and show the fixed day difference.

data.frame:

Start_Date  Difference  Status
1/1/2018    16  Fail
1/1/2018    16  Fail
1/1/2018    16  Pass
1/1/2018    16  Pass
5/1/2018    12  Fail
5/1/2018    12  Fail
5/1/2018    12  Fail
5/1/2018    12  Pass
10/1/2018   7   Pass
10/1/2018   7   Pass
10/1/2018   7   Pass
10/1/2018   7   Fail

I used today Sys.Date(), so the pass status row will keep the days difference and the fail status row will keep on date counting. I tired:

If (df$Status == "Pass") { df$Difference <- "I have not idea" } else { df$Difference <- Sys.Date()-df$Start_Date }

something like that, any advise ? Thanks.

Aucun commentaire:

Enregistrer un commentaire