I want R to replace rows with NA values if the column name matches the row name of another column. For instance, if individual 123 was last registered in array 6 (Very.last=Last.6), it will replace the time in Last.6 with NAs.
E.g. Before
ID | Last.5 | Last.6 | Very.last |
---|---|---|---|
123 | 2021-05-03 | 2021-05-04 | Last.8 |
124 | 2021-04-01 | 2021-04-15 | Last.6 |
After replacing its last registrations with NA:
ID | Last.5 | Last.6 | Very.last |
---|---|---|---|
123 | 2021-05-03 | 2021-05-04 | Last.8 |
123 | 2021-04-01 | NA | Last.6 |
Any suggestions?
Have tried using dplyr::filter
, but not sure how to filter based on the row name matching a column name for a certain individual.