Learn R Programming

SciencesPo (version 1.02.12)

slice: Slice a vector

Description

Break up a vector by certain N sized chunks.

Usage

slice(x, by = 2, pattern = NULL)

Arguments

x
A numeric vector
by
The number by which to split the vector
pattern
The number of blocks

encoding

UTF-8

Details

When using pattern, the formule used to break the vector is length(x)/pattern)+1.

Examples

Run this code
x <- seq(1:15)
slice(x, by = 2)
slice(x, pattern = 4)
slice(sample(x), by= 2) # draw random pairs

Run the code above in your browser using DataLab