Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Replicating a Value to the Specified Length in R Programming – rep_len() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

rep_len() function in R Language is used to replicate a given value in the specified length.

Syntax: rep_len(x, length.out)

Parameters:
x: specified value
length.out: specified number of items get printed

Example 1:




# R program to illustrate
# rep_len function
  
# Calling the rep_len() function
rep_len(1:5, 5)
rep_len(1:5, 7)
rep_len(1:5, 10)

Output:

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

Example 2:




# R program to illustrate
# rep_len function
  
# Calling the rep_len() function
rep_len(c(1, 2), 4)
rep_len(c(1, 2, 3), 5)
rep_len(c(5), 6)

Output:

[1] 1 2 1 2
[1] 1 2 3 1 2
[1] 5 5 5 5 5 5
My Personal Notes arrow_drop_up
Last Updated : 24 Jun, 2020
Like Article
Save Article
Similar Reads