Open In App

Create Repetitions of a String in R Programming – strrep() Function

Last Updated : 05 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

strrep() Function in R Language is used to create specified number of repetitions of a specified string.

Syntax: strrep(string, n)

Parameter:
string: specified string
n: number of repetitions

Example 1:




# R Program to illustrate 
# the use of strrep function
  
# String to be repeated
x <- "Geeks"
  
# Calling strrep() function
strrep(x, 5)


Output:

[1] "GeeksGeeksGeeksGeeksGeeks"

Example 2:




# R Program to illustrate 
# the use of strrep function
  
# String to be repeated
x <- "Geeks"
y <- "4 "
  
# Calling strrep() function
strrep(x, 5)
strrep(y, 5)
strrep(x, 5)


Output:

[1] "GeeksGeeksGeeksGeeksGeeks"
[1] "4 4 4 4 4 "
[1] "GeeksGeeksGeeksGeeksGeeks"

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads