What is the rep_len() function in R?
Overview
The rep_len() function in R returns the desired length of a vector object's replicated values.
Syntax
The rep_len() function takes the following syntax:
rep_len(x, length.out)
The syntax for the rep_len() function in R
Parameter value
The rep_len() function takes the following parameter values:
x: This is the vector object to be replicated.length.out: This is the desired length of the replicate object or the output vector.
Return value
The rep_len() function returns an object type that is the same as the input vector, x.
Example
# A code to illustrate the rep_len() function# creating an input vectora <- 1:5# creating a replicate of length 10replica <- rep_len(a, 10)# printing the replicatereplica
Explanation
- Line 4: We create an input vector,
a. - Line 7: We create a replicate
awith the desired length of10. We assign the result to a variable,replica. - Line 10: We print the replicate object
replica.