Concatenate 2 strings in R

0 votes

How to combine two values in R?

For example:

combine = cbind("JET", "XY")
combine
#      [,1]  [,2]
# [1,] "JET" "XY"

I want 'combine' as a single string:

combine_new = "JET,XY"

Which function shall I use?

Apr 13, 2018 in Data Analytics by BHARANI
• 400 points
44 views

1 answer to this question.

0 votes

You can use the paste() command:

You can use paste to do two things:

To concatenate values into a single "string"

example:

 paste("Hey", "Everyone", sep=" ")
[1] "Hey Everyone"

The argument sep specifies the character(s) to be used between the concatenated character vectors.

Refer the example below:

 z <- c("Hello", "Everyone")
 z
[1] "Hello" "Everyone"
paste(z, collapse="--")
[1] "Hello--Everyone"

The argument collapse specifies the character(s) to be used between the elements of the vector to be collapsed.

You can use both sep and collapse together in a single function as follows:

paste(z, "few more text", sep="|-|", collapse="--")
[1] "Hello|-|few more text--Everyone|-|few more text"

I hope this helps!

answered Apr 13, 2018 by darklord
• 6,140 points

Related Questions In Data Analytics

0 votes
1 answer

Join multiple strings in R

Joining strings in R is quite an ...READ MORE

answered Jul 19, 2018 in Data Analytics by DataKing99
• 8,130 points
48 views
0 votes
1 answer
0 votes
1 answer

Error in source("myfunction.R") : myfunction.R:2:3: unexpected symbol 1: 2: R version

Try formatting your code like this: myfunction <- ...READ MORE

answered Oct 30, 2018 in Data Analytics by Maverick
• 10,040 points
193 views
0 votes
1 answer

How to split strings in R?

You can use the  strsplit method to do ...READ MORE

answered Mar 29 in Data Analytics by Sophie may
• 9,530 points
25 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
145 views
0 votes
1 answer
0 votes
1 answer

How to change y axis max in time series using R?

The axis limits are being set using ...READ MORE

answered Apr 3, 2018 in Data Analytics by darklord
• 6,140 points
98 views
0 votes
2 answers

How to count unique values in R?

You can try this way, as.data.frame(v) %>% count(v) READ MORE

answered Aug 8 in Data Analytics by anonymous
1,263 views