Hi,
I have this task. My real file contains thousands of DF.URNs. I need to add a variable flagging that the same DF.URN appears in two IntYears with following conditions:
If only in 2018 so (2018>0 and 2019=0) Retention="Old",
If only in 2019 so (2019>0 and 2018=0) Retention="New",
If in 2018 and 2019 so (2018>0 and 2019>0) Retention="Same",
If neither in 2018 and 2019 so (2018=0 and 2019=0) Retention="No info".
I have this dummy file with a few records only:
data.source <- data.frame(stringsAsFactors=FALSE,
DF.URN = c("aaa", "aaa", "ccc", "ddd",
"ccc", "eee"),
Rec_Score = c(90, 100, 90, 90, 100, 80),
IntYear = c(2018, 2019, 2019, 2018, 2019, 2017))
data.source
table(data.source$DF.URN,data.source$IntYear)
As a result I should get
"aaa" is "Same", "ccc" is "New", "ddd" is "Old" and "eee" is "No Info"
Is it easy to do?