Skip to content
Related Articles

Related Articles

Improve Article

Replicating a Value specified number of times in R Programming – rep.int() Function

  • Last Updated : 24 Jun, 2020

rep.int() function in R Language is used to replicate a given value into a specified number of times.

Syntax: rep.int(x, times)

Parameters:
x: specified value
times: specified number of times the value get printed

Example 1:




# R program to illustrate
# rep.int function
  
# Calling the rep.int() function
rep.int(1:2, 2)
rep.int(1:3, 1)
rep.int(0:1, 4)

Output:

[1] 1 2 1 2
[1] 1 2 3
[1] 0 1 0 1 0 1 0 1

Example 2:




# R program to illustrate
# rep.int function
  
# Calling the rep.int() function
rep.int(c(1, 2), 2)
rep.int(c(1, 2, 3), 3)
rep.int(c(5), 6)

Output:

[1] 1 2 1 2
[1] 1 2 3 1 2 3 1 2 3
[1] 5 5 5 5 5 5
My Personal Notes arrow_drop_up
Recommended Articles
Page :