Method 3 : Using paste along with replicate
This paste is used to organize the repeated strings in the correct way, It will separate the strings with the given delimiter.
Syntax:
paste(replicate(N, “string”), collapse = “delimiter”)
where,
- paste is used to display the data
- replicate is used to get the N character strings
- collapse is used to separate the strings
Example: R program to repeat the character strings using paste command
R
# get 2 times with delimiter -- paste ( replicate (2, "Geek" ), collapse = "--" ) print ( "-----" ) # get 10 times with delimiter , paste ( replicate (2, "Python" ), collapse = "," ) |
Output:
[1] “Geek–Geek”
[1] “—–“
[1] “Python,Python”
Repeat Character String N Times in R
In this article, we will discuss how to repeat the character string N times in the R programming language. Character string means a set of characters .
Example:
“Hello Geek”,”Python”,”Languages_Python” are some examples
Contact Us