Search code examples
rvectorconcatenation

Elementwise Concatenation of vectors in R


I have two vectors a <- "GT001042-0000100" "GT001049-0000300" "GT001056-0000700" b <- GTL2 GTNP GTL2

I need output in the form of - out <- "GT001042-0000100GTL2" "GT001049-0000300GTNP" "GT001056-0000700-GTL2" How do I do that in R? Someone please help.


Solution

  • Paste0 should do the job:

    output = paste0(a,b)
    

    Or more general paste if you want to add a seperator between the strings:

    output = paste(a, b, sep="-")