Concatenate two or more Strings in R programming language

We shall learn to Add or Concatenate two or more Strings in R programming Language using paste function.

Concatenate two or more Strings in R

Following is the syntax of paste function that is used to concatenate two or more strings.

paste(…, sep=””, collapse=NULL)

where

pasteis the keyword
sepis a character that would be appended between two adjacent strings and acts as a separator
collapseis an optional character to separate the results

 

Example R script to concatenate two strings in R programming language

The default separator in paste function is space (” “). So ‘Hello’ and ‘World!’ are joined with space in between them.

 

Example R script to concatenate two strings in R programming language with no separator

Please observe that we have overwritten default separator in paste function with “”. So ‘Hello’ and ‘World!’ are joined with nothing in between them.

 

Example R script to concatenate more than two strings in R programming language

You may provide as many number of strings as required to the R paste function to concatenate.

 

Conclusion :

In this R Tutorial, we have learnt to concatenate two or more strings using R paste function.