R: Expand the length of a vector

vec_repeat {vctrs} | R Documentation

## Expand the length of a vector

### Description

This is a special case of `rep()` for the special case of integer `times` and `each` values, and works along size, rather than length.

### Usage

    vec_repeat(x, each = 1L, times = 1L)

### Arguments

`x` | A vector.
`each` | Number of times to repeat each element of `x`.
`times` | Number of times to repeat the whole vector of `x`.

### Value

A vector the same type as `x` with size `vec_size(x) * times * each`.

### Examples

    # each repeats within
    vec_repeat(1:3, each = 2)
    # times repeats whole thing
    vec_repeat(1:3, times = 2)

    df <- data.frame(x = 1:2, y = 1:2)
    # rep() repeats columns of data frame, and returns list:
    rep(df, each = 2)
    # vec_repeat() repeats rows, and returns same data.frame
    vec_repeat(df, 2)

[Package vctrs version 0.2.4 Index]