I got stuck on some string similarity issues.
This is how my data looks like (the original data is huge):
SerialNumber SubSerialID Date
AGCC0775CFNDA1040TMT775 AVCC0775CFNDA1040 2018/01/08
AGCC0775CFNDA1040 AVCC0775CFNDA1040 2015/12/28
AGCC0775CFNDA10407EC AVCC0775CFNDA1040 2018/03/17
CH~MT765E~C0765HFNCC1056 BGDC0865HFNKG1043 2019/01/07
2658358 BGDC0865HFNKG1043 2018/08/09
MT765E~C0765KFNCD1044 C0765KFNCD10 2015/04/07
187A126 C0765KFNCD10 2017/11/31
...
My target is:
SerialNumber SubSerialID Date
AGCC0775CFNDA10407EC AVCC0775CFNDA1040 2018/03/17
CH~MT765E~C0765HFNCC1056 BGDC0865HFNKG1043 2019/01/07
2658358 BGDC0865HFNKG1043 2018/08/09
MT765E~C0765KFNCD1044 C0765KFNCD10 2015/04/07
187A126 C0765KFNCD10 2017/11/31
...
Serial Numbers AGCC0775CFNDA1040TMT775
, AGCC0775CFNDA1040
, and AGCC0775CFNDA10407EC
are the same thing but caused by mistakes. I want to keep AGCC0775CFNDA10407EC
because it has the latest date on record. However, I cannot use SubSerialID
and Date
directly to filter those Serial Numbers because if will remove 2658358
.
I thought about using stringdist
to find string similarity as another condition (i.e., filter out by abs (similarity) >1.5 and abs (similarity)<0.5) but cannot figure out an efficient way to handle it. The data it's huge and using for loop is unpragmatic. I got stuck for a while and hopefully, someone can give me some advice or suggestion with this matter.