在 R 编程中创建字符串的重复 – strrep()函数
R 语言中的strrep()
函数用于创建指定字符串的指定重复次数。
Syntax: strrep(string, n)
Parameter:
string: specified string
n: number of repetitions
示例 1:
# R Program to illustrate
# the use of strrep function
# String to be repeated
x <- "Geeks"
# Calling strrep() function
strrep(x, 5)
输出:
[1] "GeeksGeeksGeeksGeeksGeeks"
示例 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)
输出:
[1] "GeeksGeeksGeeksGeeksGeeks"
[1] "4 4 4 4 4 "
[1] "GeeksGeeksGeeksGeeksGeeks"