The rep
function in R replicates the values in a given vector.
The rep
function takes the following syntax:
rep.int(x, times)
The rep()
function takes the following parameter values:
x
: This is the input vector whose values are to be replicated.times
: This specifies the number of times the value of x
has been replicated. The rep()
function returns an object of the same type as the input vector x
.
# A code to illustrate the rep() function in R# creating a vector objecta <- 1:5# replicating the values in a by 2 timesb <- rep(a, 2)b
a
.rep()
function to create a replicate of the values of a
. The result is assigned to a variable, b
.b
.