How to concatenate strings based on overlap in R?

Viewed 193

I have three diferent strings that match and overlap along the caracteres

a = 'ABCDEF'
b = 'DEFGHI'
c = 'FGHIJK'

How can I combine these strings to have this output?

match
[1] 'ABCDEFGHIJK'
1 Answers

One option could be:

paste(Reduce(union, sapply(list(a, b, c), strsplit, "")), collapse = "")

[1] "ABCDEFGHIJK"
Related