Skip to contents

This function splits a vector at specific positions.

Usage

split_vector_at(x, at)

Arguments

x

[atomic()`]
A vector of elements.

at

[integer()]
Index position(s) just before to split.

For example, at = n splits before the nth element of x.

Value

A list.

References

Based on https://stackoverflow.com/a/19274414.

Examples

x <- 1:10
split_vector_at(x, c(2, 3, 5, 7))
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 2
#> 
#> [[3]]
#> [1] 3 4
#> 
#> [[4]]
#> [1] 5 6
#> 
#> [[5]]
#> [1]  7  8  9 10
#>