Extract characters that differ between two strings

后端 未结 6 1961
小蘑菇
小蘑菇 2020-12-03 08:09

I have used adist to calculate the number of characters that differ between two strings:

a <- \"Happy day\"
b <- \"Tappy Pay\"
adist(a,b)          


        
6条回答
  •  猫巷女王i
    2020-12-03 08:52

    You can use one of the variables as a regex character class and gsub out from the other one:

    gsub(paste0("[",a,"]"),"",b)
    [1] "TP"
    gsub(paste0("[",b,"]"),"",a)
    [1] "Hd"
    

提交回复
热议问题