Hello R community, I really need your help to solve this problem.
I want to filter Patient_ID and Date_Supplied in Main_table by looking up in Lookup_table with following conditions:
- Patient_ID with its corresponding Date_Supplied in Main_table should match in Lookup_table
- All the matching Patient_ID with its corresponding Date_Supplied should be filtered in Main_table
- All Date_Supplied thereafter for that Patient_ID should be filtered in Main_table
Solution using tidyverse package would be awesome!
Main_table:
library(tidyverse)
library(datapasta)
Main_table <- tibble::tribble(
~Patient_ID, ~Date_Supplied,
1L, "2/10/2015",
1L, "3/10/2015",
1L, "4/10/2015",
2L, "5/10/2015",
2L, "6/10/2015",
2L, "7/10/2015",
2L, "8/10/2015",
2L, "9/10/2015",
3L, "1/12/2017",
3L, "2/12/2017",
3L, "3/12/2017",
4L, "1/10/2018",
4L, "2/10/2018",
4L, "3/10/2018"
)
Lookup_table:
Lookup_table <- tibble::tribble(
~Patient_ID, ~Date_Supplied,
1L, "2/10/2015",
2L, "7/10/2015",
4L, "3/10/2018"
)
Expected Output:
Expected_output <- tibble::tribble(
~Patient_ID, ~Date_Supplied,
1L, "2/10/2015",
1L, "3/10/2015",
1L, "4/10/2015",
2L, "7/10/2015",
2L, "8/10/2015",
2L, "9/10/2015",
4L, "3/10/2018"
)
Thank you