R语言 创建字符串的重复 – strrep()函数
R语言中的 strrep() 函数用于创建一个指定字符串的指定数量的重复。
语法: strrep(string, n)
参数:
string: 指定的字符串
n: 重复的数量
例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"