0

I have 2 columns in a dataset, both values are in chr. I need to create a new column with longest starting(initial) substring. Example.

A............... B.......... C.

Australia Austria Austr

Network Netconnect Net

New column name is C, which I want to create. In column C, common starting strings(Austr, Net)from A and B is updated.No of rows are 10k in my dataset.

  • 1
    copy of https://stackoverflow.com/questions/28261825/longest-common-substring-in-r-finding-non-contiguous-matches-between-the-two-str – abhiieor Jun 06 '18 at 09:20
  • 1
    @docendodiscimus found another, seems a better fit to me; what do you think? – Jaap Jun 06 '18 at 09:30

1 Answers1

0

Split the characters of the words from A and B and use a loop to compare each characters. And append matched characters in the new column C.

Something like list1=['n','e','t','w','o','r','k'] and list2=['n','e','t','c','o','n','n','c','t']

now if(list1[i]==list2[i] then list3.append(list1[i])

and keep list 3 in the column 3.