i have a dataframe with basically two columns and "dates" in one and "grade of disease" in the other.
They are coded as follows:
Date | Grade |
---|---|
2017-10-14=&=2018-01-20=&==&= | 1=&=2=&==&= |
2018-10-14=&=2019-01-20=&=2020-01-01=&= | 2=&=3=&=4=&= |
I look for a code to access the date from the first column that corresponds to the Grade in the second columns. Additionally it would be a great help to be able to extract the date, when Grade of disease was e.g. 2 for the first time.
I tried str_split(... sep = "=&=) and end up with a matrix with all different dates and grades.
I would need to extract the following:
- For time-varying analysis
Follow_up_1 | Grade_1 | Follow_up_2 | Grade_2 | Follow_up_3 | Grade_3 |
---|---|---|---|---|---|
2017-10-14 | 1 | 2018-01-20 | 2 | NA | NA |
2018-10-14 | 2 | 2019-01-20 | 3 | 2020-01-01 | 4 |
- Date of max_grade and max_grade
Date_max_grade | Max_grade |
---|---|
2018-01-20 | 2 |
2020-01-01 | 4 |
- Extract the first date, where the corresponding grade is 3 or 4.
First_Date_3_or_4 |
---|
NA |
2019-01-20 |
2020-01-01 |
Thanks in advance,
Jan