How to Repeat a Character String N Times in R (2 Examples)
This page explains how to repeat the elements of a character string multiple times in the R programming language.
Construction of Exemplifying Data
x <- "Laaa" # Exemplifying character string in R x # Display character string in RStudio console # [1] "Laaa" |
x <- "Laaa" # Exemplifying character string in R x # Display character string in RStudio console # [1] "Laaa"
Example 1: Using rep() Function to Create Vector of Character Strings Containing Multiple Repetitions
rep(x, 3) # Apply rep() function # [1] "Laaa" "Laaa" "Laaa" |
rep(x, 3) # Apply rep() function # [1] "Laaa" "Laaa" "Laaa"
Example 2: Using strrep() Function to Create Single Character String Containing Multiple Repetitions
strrep(x, 3) # Apply strrep() function # [1] "LaaaLaaaLaaa" |
strrep(x, 3) # Apply strrep() function # [1] "LaaaLaaaLaaa"
Related Articles
Here, you may find some additional resources that are similar to the topic of this page.