I'm trying to conduct a text string search based on 1 column value (1st data frame) if it partially or fully matches with another column (in 2nd data frame) (not via keywords). Both datasets are different in size. (Using R 3.5.1)
Working on 2 datasets which are 900K and 80 K observations each. First dataset has column that contains a product code (prod_code: ABC-1562) and the second one has column containing Family_code (family_code: ABC-1563; ABC-1562; ABC-9892). Both tables has a product identification number (prod id: 4772345) assigned to each unique product code.
I tried using charmatch, match, string_detect but so far I couldn't make any head with my code.
Using match
df2<- df2%>% mutate_(check = match(df1$prod_code, df2$family_code)
Using charmatch
df1$char_match <- charmatch(df1$prod_code, df2$family_code)
Using str_detect
df1%>% mutate (String_check = str_detect(df2$family_code, df1$prod_code))
Expected Result
I need to query: 1. If the value from 1st column (Product code) exists in 2nd column (Family Code) 2. Store the output in column if Product code exists in string of Family
code.
product_code (1st Dataset)
Obs 1- ABC-1562
Obs n- ABC-1562
family_code (2nd Dataset)
Obs 1- ABC-1563; ABC-1562; ABC-9892
Obs n- ABC-1563; ABC-1564; ABC-9892
QC (Match Result)
Obs 1- TRUE Obs n- FALSE
QC can either be Boolean or numeric, both cases will suffice.
Thanks in advance!