Использование data.table:
РЕДАКТИРОВАТЬ: Я отредактировал ваши образцы данных для учета возможных причин множественных причин. В этих данных ID==1
соответствует как R2, так и R3.
Данные
ID = c(1, 2, 3, 4)
Issues = c('Issue1, Issue4, Issue6, Issue7', 'Issue2, Issue5, Issue6', 'Issue3, Issue4', 'Issue1, Issue5')
Location = c('x', 'y', 'z', 'w')
Customer = c('a', 'b', 'c', 'd')
DF1 = data.table(ID, Issues, Location, Customer)
Root_Cause = c('R1', 'R2', 'R3', 'R4')
List_of_Issues = c('Issue1, Issue3, Issue5', 'Issue2, Issue1, Issue4', 'Issue6, Issue7', 'Issue5, Issue6')
DF2 = data.table(Root_Cause, List_of_Issues)
Код
DF1[, Issues := strsplit(Issues, split = ', ')]
DF2[, List_of_Issues := strsplit(List_of_Issues, split = ', ')]
DF1[, RootCause := lapply(Issues, function(x){
matchvec = sapply(DF2[, List_of_Issues], function(y) length(unlist(intersect(y, x))))
ids = which(matchvec > 1)
str = DF2[, paste(Root_Cause[ids], collapse = ', ')]
ifelse(str == '', NA, str)
})]
Результат
> DF1
ID Issues Location Customer RootCause
1: 1 Issue1,Issue4,Issue6,Issue7 x a R2, R3
2: 2 Issue2,Issue5,Issue6 y b R4
3: 3 Issue3,Issue4 z c NA
4: 4 Issue1,Issue5 w d R1