Replicating a Value specified number of times in R Programming – rep.int() Function
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 ) |
chevron_right
filter_none
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 ) |
chevron_right
filter_none
Output:
[1] 1 2 1 2 [1] 1 2 3 1 2 3 1 2 3 [1] 5 5 5 5 5 5