R: Repeatedly slice a vector

vec_chop {vctrs} | R Documentation

## Repeatedly slice a vector

### Description

`vec_chop()` provides an efficient method to repeatedly slice a vector. It captures the pattern of `map(indices, vec_slice, x = x)`.

### Usage

    vec_chop(x, indices = NULL)

### Arguments

`x` | A vector
`indices` | A list of index values to slice `x` with, or `NULL`. Each element of the list must be an integer, character or logical vector that would be valid as an index in `vec_slice()`. If `NULL`, `x` is split into its individual elements, equivalent to using an `indices` of `as.list(vec_seq_along(x))`.

### Value

A list of size `vec_size(indices)` or, if `indices == NULL`, `vec_size(x)`.

### Examples

    vec_chop(1:5)
    vec_chop(1:5, list(1, 1:2))
    vec_chop(mtcars, list(1:3, 4:6))

[Package vctrs version 0.2.2 Index]