How to Apply the rep() Function in R (3 Examples)

In this tutorial you’ll learn how to apply the rep function in the R programming language.

Example 1: Applying rep Function with times Argument

rep(1:5, times = 2)        # times argument
# 1 2 3 4 5 1 2 3 4 5

Example 2: Applying rep Function with each Argument

rep(1:5, each = 2)         # each argument
# 1 1 2 2 3 3 4 4 5 5

Example 3: Applying rep Function with len Argument

rep(1:5, len = 13)         # len argument
# 1 2 3 4 5 1 2 3 4 5 1 2 3

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top