Extract characters that differ between two strings

后端 未结 6 1949
小蘑菇
小蘑菇 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条回答
  •  醉梦人生
    2020-12-03 08:41

    You can use the following sequence of operations:

    • split the string using strsplit().
    • Use setdiff() to compare the elements
    • Wrap in a reducing function

    Try this:

    Reduce(setdiff, strsplit(c(a, b), split = ""))
    [1] "H" "d"
    

提交回复
热议问题