Replicate a value n times

Here we will replicate some values n times.

Example:

R




# replicate 3 value 5 times
print(replicate(5, 3))
 
# replicate  akash 5 times
print(replicate(5, "akash"))
 
# replicate  TRUE 5 times
print(replicate(5, TRUE))


Output:

[1] 3 3 3 3 3
[1] "akash" "akash" "akash" "akash" "akash"
[1] TRUE TRUE TRUE TRUE TRUE

How to Use the replicate() Function in R?

replicate() function in R Programming Language is used to evaluate an expression N number of times repeatedly.

Syntax:

replicate(n, expression)

where

  • expression is a statement to evaluate
  • n is the number of times to evaluate the expression

Similar Reads

Method 1: Replicate a value n times

Here we will replicate some values n times....

Method 2: Replicate a Function Multiple Times

...