[R] greatest common substring

Jonne Zutt j.zutt at tudelft.nl
Tue Nov 14 12:36:05 CET 2006


Dear R-members,

Suppose I have a vector with the following strings:
V = c("Welfare_Group_1024",
      "Welfare_Group_1536",
      "Welfare_Group_160")

I want to 'automatically generate a nice y-axis label for this data.
A good candidate is something close to "Welfare Group".

Is there an easy way to compute something close to the greatest
common substring?
It would be nice if it also works in this case:
V = c("xxxWelfare_Group_1024",
      "yWelfare_Group_1536",
      "zzzzzWelfare_Group_160")

Should I iterate through all possible substrings in the first element,
to see whether this substring is part of all other strings?
I was hoping for some existing R function :)

Thanks in advance,
JeeBee.



More information about the R-help mailing list