Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

element-wise concatenation of string vectors [duplicate]

Tags:

r

Say I have two character vectors:

a <- c("a", "b", "c") b <- c("1", "2", "3") 

How do I merge them such that I get:

ab <- c("a1", "b2", "c3") 
like image 449
dvmlls Avatar asked Dec 04 '13 19:12

dvmlls


People also ask

Can you concatenate more than 2 strings?

Concatenation operator || In addition to the CONCAT() function, Oracle also provides you with the concatenation operator ( || ) that allows you to concatenate two or more strings in a more readable fashion: string1 || string2 || string3 || ...

Which is an example of string concatenation?

In formal language theory and computer programming, string concatenation is the operation of joining character strings end-to-end. For example, the concatenation of "snow" and "ball" is "snowball".

How do you concatenate vectors?

The concatenation of vectors can be done by using combination function c. For example, if we have three vectors x, y, z then the concatenation of these vectors can be done as c(x,y,z). Also, we can concatenate different types of vectors at the same time using the same same function.


1 Answers

You can use paste or paste0:

> a <- c("a", "b", "c") > b <- c("1", "2", "3") > paste0(a, b) [1] "a1" "b2" "c3" >  
like image 115
Justin Avatar answered Sep 21 '22 23:09

Justin