I need to find info from a data.frame into another data.frame. The idea is to see if the info is included in both data.frames and if not detect that. To expose my issue I have created a short reprex:
segment_name<-data.frame(stringsAsFactors=FALSE,
Segment_1 = c("XILTI_ARTAT", "XILTI_ARTAT", "XILTI_ARTAT", "XILTI_ARTAT",
"XILTI_ARTAT", "XILTI_ARTAT", "XILTI_ARTAT", NA, NA),
Segment_2 = c("ZAG_VBA", "ZMR_ORBIS", "ZWN_PIREK", "VERCE_MLP.A",
"VERED_BMN.A", "VERED_WSN", "VEREV_GIMEX", NA, NA)
)
conflict<- data.frame(stringsAsFactors=FALSE,
Conflict_1 = c("XILTI_ARTAT", "VEREV_PITAL", "XILTI_ARTAT", "IFDPS_DFTGS",
"ASGSH_SADCU", "XILTI_ARTAT", "ASDCI_ASDED", "FOFNV_VSDFO",
"VERCE_MLP.A"),
Conflict_2 = c("VEREV_GIMEX", "VKWES_ACOFS", "ZAG_VBA", "SCVVR_VLOCS",
"BFDND_VLOSN", "VERED_BMN.A", "QFDHS_DCVSO", "SDVSJ_SDCVS",
"XILTI_ARTAT")
)
result<- data.frame(stringsAsFactors=FALSE,
Conflict_1 = c("XILTI_ARTAT", "VEREV_PITAL", "XILTI_ARTAT",
"IFDPS_DFTGS", "ASGSH_SADCU", "XILTI_ARTAT",
"ASDCI_ASDED", "FOFNV_VSDFO", "VERCE_MLP.A"),
Conflict_2 = c("VEREV_GIMEX", "VKWES_ACOFS", "ZAG_VBA", "SCVVR_VLOCS",
"BFDND_VLOSN", "VERED_BMN.A", "QFDHS_DCVSO",
"SDVSJ_SDCVS", "XILTI_ARTAT"),
CATEGORIZATION = c("FOUND", "NOT FOUND", "FOUND", "NOT FOUND", "NOT FOUND",
"FOUND", "NOT FOUND", "NOT FOUND", "FOUND")
)
Info from the first two columns of both data.frames are ligated and should be analyzed together, that is to say:
Segment_1+Segment_2 = XILTI_ARTAT + ZAG_VBA
This combination is the one that should be searched into the data.frame "conflict", whose two columns are also ligated: Conflict_1+Conflict_2.
Important to note that combinations should be searched also in an opposite way, that is to say for the example above: Segment_1+Segment_2 = XILTI_ARTAT + ZAG_VBA is the same combination that Segment_2+Segment_1 = ZAG_VBA + XILTI_ARTAT and therefore, both possibilities should be searched in the data.frame "conflict".
The solution is presented in the 3rd data.frame, "result". There, combination Segment1+Segment2 was searched in Conflict1+Conflict2. As can be seen in the column "CATEGORIZATION", combinations were identified as "Found" and "Not Found". Finally, "Founds" were identified in another column, also showed in the reprex.