Replicate elements of vector in R programming – rep() Method

With the help of

method, we can replicate the elements of vectors in R programming.**rep()**

Syntax:`rep(x, times)`

Return:Returns the replicated vectors.

**Example 1:**

`# Using rep() method` `x <` `-` `rep(` `1` `:` `5` `)` ` ` `gfg <` `-` `rep(x, ` `2` `)` ` ` `print` `(gfg)` |

**Output:**

[1] 1 2 3 4 5 1 2 3 4 5

**Example 2:**

`# Using rep() method` `x <` `-` `rep(` `-` `10` `:` `-` `5` `)` ` ` `gfg <` `-` `rep(x, ` `3` `)` ` ` `print` `(gfg)` |

**Output:**

[1] -10 -9 -8 -7 -6 -5 -10 -9 -8 -7 -6 -5 -10 -9 -8 -7 -6 -5