To Repeat the string of the column in R, we use str_dup() function of “stringr” package. In this tutorial we will be looking on how to repeat the string of column in R with an example
Let’s first create the dataframe
df1 = data.frame(State = c('Arizona','Georgia', 'Newyork','Indiana','Florida'), Score=c(62,47,55,74,31)) df1
df1 will be
Repeat the string of the column in R:
str_dup() function of “stringr” package is used to repeat the string column in R
## Repeat the string of the column in R library(stringr) df1$repeat_state= str_dup(df1$State,2) df1
Argument 2 indicates repeating twice, so the resultant dataframe will be