VOOZH about

URL: https://www.geeksforgeeks.org/r-language/string-concatenation-in-r-programming/

⇱ String Concatenation in R Programming - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

String Concatenation in R Programming

Last Updated : 12 Jul, 2025

String concatenation is a way of appending two or more strings into a single string whether it is character by character or using some special character end to end. There are many ways to perform string concatenation. 

Example:

Input: str1 = 'Geeks'
str2 = 'for'
str3 = 'Geeks' 
Output: 'GeeksforGeeks'

To perform concatenation in R we use the paste() function which can combine two or more strings together. It takes different types of arguments as follows:

Syntax: paste(string1, string2, ....stringn, sep = "", collapse=NULL) 

Parameters: 
string1, string2...string3: Strings provided for concatenation. 
sep: the type of separator we use. 
collapse: defines how to separate the result element-wise in the vector of string.

Concatenate two strings

Output:

"GeeksforGeeks"
"Geeks#forGeeks"

Concatenation using different types of separator

With the help of paste() function we can perform concatenation by using different types of separators like whitespace or some special characters. 

Output:

Hello World
Hello, World

Concatenating more than two strings

With the help of paste() function we can concatenate more than two strings. 

Output:

I Love Programming

cat() Function

Similarly, we can perform concatenation using cat() function with the help of which we can perform character-wise concatenation and it also gives us the flexibility to save the result in a file.

Syntax: cat(string1, string2, ...string, sep = '', file, append) 

Parameters: 
string1, string2...string3: Strings provided for concatenation. 
sep: the type of separator we use. 
file: used to save the result in a file with a specified name. 
append: logical argument to specify if you want to append the result in an existing file or create a new file.

Concatenating two or more strings using cat() function.

We can perform concatenation by inserting the variable name of the string and specifying the separator.we can insert more than two variables also and specify different types of parameter. 

Output:

Competitive Coding is difficult

Saving the concatenated result in a file

To save the result of the concatenated output we can specify the name of the file in the argument. By default the append is false, but if you want to append the result into an existing file then specify append as TRUE. The result will be saved into the specified file format. 

Output:

 👁 Image

Comment
Article Tags:

Explore