Skip to content
Related Articles

Related Articles

Improve Article
Replicate elements of vector in R programming – rep() Method
  • Last Updated : 10 May, 2020

With the help of rep() method, we can replicate the elements of vectors in R programming.

Syntax: rep(x, times)
Return: Returns the replicated vectors.

Example 1:




# Using rep() method
x <- rep(1:5)
  
gfg <- rep(x, 2)
  
print(gfg)

Output:

[1] 1 2 3 4 5 1 2 3 4 5

Example 2:




# Using rep() method
x <- rep(-10:-5)
  
gfg <- rep(x, 3)
  
print(gfg)

Output:

[1] -10  -9  -8  -7  -6  -5 -10  -9  -8  -7  -6  -5 -10  -9  -8  -7  -6  -5
My Personal Notes arrow_drop_up
Recommended Articles
Page :