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:
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:
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
Share your thoughts in the comments
Please Login to comment...