I have longitudinal patient data in R. I would like to create an end_date variable (4th column in table below) from the three different dates I already have, whichever occurred first, and in case death or transfer didn't occur, end_date would equal to data_collection_end_date:
| patid | death_date | transfer_date | data_collection_end_date | end_date |
|---|---|---|---|---|
| 1 | 07/07/2018 | 07/07/2016 | 01/11/2021 | 07/07/2016 |
| 2 | 07/07/2019 | 07/07/2018 | 01/11/2021 | 07/07/2018 |
| 3 | 07/07/2020 | 07/07/2018 | 01/11/2021 | 07/07/2018 |
| 4 | NA | NA | 01/12/2021 | 01/12/2021 |
| 5 | NA | NA | 01/11/2021 | 01/11/2021 |
| 6 | NA | 07/09/2016 | 01/11/2021 | 07/09/2016 |