R: Create vectors matching the length of a given vector

new-vector-along {rlang} | R Documentation

## Create vectors matching the length of a given vector

### Description

These functions take the idea of `seq_along()` and generalise it to creating lists (`new_list_along`) and repeating values (`rep_along`). Except for `new_list_along()` and `new_raw_along()`, the empty vectors are filled with typed `missing` values.

### Usage

    new_logical_along(x, names = base::names(x))

    new_integer_along(x, names = base::names(x))

    new_double_along(x, names = base::names(x))

    new_character_along(x, names = base::names(x))

    new_complex_along(x, names = base::names(x))

    new_raw_along(x, names = base::names(x))

    new_list_along(x, names = base::names(x))

    rep_along(.x, .y)

### Arguments

`x, .x` | A vector.
`names` | Names for the new vector. Defaults to the names of `x`. This can be a function to apply to the names of `x` as in `set_names()`.
`.y` | Values to repeat.

### See Also

new-vector

### Examples

    x <- 0:5
    rep_along(x, 1:2)
    rep_along(x, 1)
    new_list_along(x)

    # The default names are picked up from the input vector
    x <- c(a = "foo", b = "bar")
    new_character_along(x)

[Package rlang version 0.2.2 Index]