str_c() Function of stringr Package in R
In this article, we will discuss str_c() function which is available in stringr package. Before going to this method, we have to install and import stringr package.
Syntax:
Install- install.packages("stringr")
Import - library("stringr")
str_c() Methods
This function is used to combine the multiple strings by a separator.
Syntax:
str_c(“string1″,”string2”,……………,sep)
where,
strings are the input strings separated by comma and sep is the second parameter used to separate deach string with a delimiter.
Example 1:
In this example, we are concatenating 5 strings without separator.
R
library (stringr)
print ( str_c ( "Welcome" , "to" , "geeks" ,
"for" , "geeks" ))
|
Output:
[1] "Welcometogeeksforgeeks"
Example 2:
In this example, we are concatenating 5 strings by different separators.
R
library (stringr)
print ( str_c ( "Welcome" , "to" , "geeks" ,
"for" , "geeks" ,sep= "," ))
print ( str_c ( "Welcome" , "to" , "geeks" ,
"for" , "geeks" ,sep= " " ))
print ( str_c ( "Welcome" , "to" , "geeks" ,
"for" , "geeks" ,sep= "&" ))
|
[1] "Welcome,to,geeks,for,geeks"
[1] "Welcome to geeks for geeks"
[1] "Welcome&to&geeks&for&geeks"
Last Updated :
02 Jun, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...