This question is just asking for an implementation in R of the following question : Find the longest common starting substring in a set of strings (JavaScript)
"This problem is a more specific case of the Longest common substring problem. I need to only find the longest common starting substring in an array".
So im just looking an R implementation for this question (preferably not in a for / while loop fashion that was suggested in the JavaScript version), if possible i would like to wrap it up as a function, so i could apply on many groups in a data table.
After some searches, i couldn't find an R example for this, hence this question.
Example Data: I have the following vector of characters:
dput(data)
c("ADA4417-3ARMZ-R7", "ADA4430-1YKSZ-R2", "ADA4430-1YKSZ-R7",
"ADA4431-1YCPZ-R2", "ADA4432-1BCPZ-R7", "ADA4432-1BRJZ-R2")
I'm looking to run an algorithm in R that will find the following output: ADA44
.
From what I've seen in the JavaScript accepted answer, the idea is to first sort the vector, extract the first and last elements (for example : "ADA4417-3ARMZ-R7"
and "ADA4432-1BRJZ-R2"
, break them into single characters, and loop through them until one of the characters don't match (hope im right)
Any Help on that would be great!