In Ruby I could repeat a String n times with the following:
E.G. "my_string" * 2 -> "my_stringmy_string"
Is there an equally simple way for doing this in R?
You can use replicate
or rep
:
replicate(2, "my_string")
# [1] "my_string" "my_string"
rep("my_string", 2)
# [1] "my_string" "my_string"
paste
will put it together:
paste(replicate(2, "my_string"), collapse = "")
# [1] "my_stringmy_string"