Open In App

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

Last Updated : 15 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
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: Python3
# 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: Python3
# 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

Article Tags :

Similar Reads