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
25 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,100 points
28 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,000 points
80 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,050 points
11 views
+13 votes
2 answers
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
42 views
0 votes
1 answer

How to count unique values in R?

You can get the information printed in ...READ MORE

answered Apr 9, 2018 in Data Analytics by darklord
• 6,140 points
662 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.