How to use rep() method In R Language

 

This function works similar to replicate .

 

Syntax:

 

rep( “string”,N)

 

Example: R program that repeats character String N times using rep

 

R




# get 2 times
print(rep("Hello_Geek", 2))
 
print("-----")
 
# get 10 times
print(rep("Python", 10))
 
print("-----")
 
# get 3 times
print(rep("java", 3))
 
print("-----")
 
# get 4 times
print(rep("dbms", 4))
 
print("-----")
 
# get 5 times
print(rep("sql", 5))
 
print("-----")
 
# get 7 times
print(rep("big data", 7))


Output:

[1] “Hello_Geek” “Hello_Geek”

[1] “—–“

[1] “Python” “Python” “Python” “Python” “Python” “Python” “Python” “Python”

[9] “Python” “Python”

[1] “—–“

[1] “java” “java” “java”

[1] “—–“

[1] “dbms” “dbms” “dbms” “dbms”

[1] “—–“

[1] “sql” “sql” “sql” “sql” “sql”

[1] “—–“

[1] “big data” “big data” “big data” “big data” “big data” “big data” “big data”

Repeat Character String N Times in R

In this article, we will discuss how to repeat the character string N times in the R programming language. Character string means a set of characters .

Example:

“Hello Geek”,”Python”,”Languages_Python” are some examples

Similar Reads

Method 1: Using replicate() method

This function used to give n replicas from the character string...

Method 2: Using rep() method

...

Method 3 : Using paste along with replicate

...

Method 4: Using strrep() function

...

Contact Us