lundi 30 novembre 2020

R - Add New column based on days in between dates

I have a data set with ID, multiple dates for COVID test for that ID, results, and a new column called CaseID.

ID      DATE            Results         CASEID
1       01/01/2020     POSITIVE           ...
1       02/12/2020     NEGATIVE           ...
1       03/01/2020     POSITIVE           ...

My question is: is there a way to say: if from the first positive for an ID (so 01/01/2020 for ID 1) is approximately 60 days, 90 days or 120 days between two positive test, then put the category "60days" or "90days" or "120days" in th column CaseID.

In this case it will be 60 days.

Is that possible?

Aucun commentaire:

Enregistrer un commentaire