2

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'
2
  • 3
    Can you be more explicit about the logic? If you input is a = 'ABCDEF' and b = 'GHIDEF', what would you expect the output to be? (i.e. what exactly is meant by "overlap"?) Commented Feb 1, 2021 at 22:24
  • Hello! Imagine that strings a, b and c are substrings and obbey that exact and specific order. By overlap I meant intersection, characters in common in a unique sense. For example, a and b overlap by "DEF", b and c overlap by "FGHI", and, if we sobrepose them, they form 'ABCDEFGHIJK'. Your example will result in none output (a = 'ABCDEF' and b = 'GHIDEF'), because they don't overlap. I want to combine them from left to right. Commented Feb 2, 2021 at 17:53

1 Answer 1

1

One option could be:

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

[1] "ABCDEFGHIJK"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.