I wonder how to dplyr::filter() my DATA to catch the rows for IDs whose Language value when 'Type!=5F' and when 'Type==5F' changes from other languages to "English"?
For example, ID==1 has Spanish when 'Type!=5F' and English when 'Type==5F'. So, we filter it.
Desired_output is below.
DATA <- read.table(header=TRUE,text="
ID Type Year Language
1 1A 1718 spansih
1 1A 1819 spanish
1 5F 1920 English
2 1B 1718 spanish
2 1B 1819 spanish
2 1B 1920 spanish
2 5F 2021 spanish
3 1B 1920 English
3 5F 2021 English")
Desired_output <- read.table(header=TRUE,text="
ID Type Year Language
1 1A 1718 spansih
1 1A 1819 spanish
1 5F 1920 English")