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?
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?
The
stringr
library offers the functionstr_dup()
:And it is vectorized over strings and times:
With
R 3.3.0
, we can usestrrep
frombase R
We can also pass a vector of values in
times
Use
stri_dup
function fromstringi
packageIt is also vectorized, so you can do this:
Performance comparision :)
You can use
replicate
orrep
:paste
will put it together: