Learn R Programming

qdapTools (version 1.3.7)

shift: Shift Vector Left/Right

Description

Shift a vector left or right n spaces.

Usage

shift(x, n, direction = "right")

shift_right(x, n)

shift_left(x, n)

Value

Returns a shifted vector.

Arguments

x

A vector.

n

The number of moves left or right to shift.

direction

A direction to shift; must be either "left" or "right". Use explicit directional shift functions shift_right and shift_left for better performance.

Examples

Run this code
lapply(0:9, function(i) shift(1:10, i))
lapply(0:9, function(i) shift(1:10, i, "left"))

## Explicit, faster shifting
lapply(0:9, function(i) shift_right(1:10, i))
lapply(0:9, function(i) shift_left(1:10, i))
lapply(0:25, function(i) shift_left(LETTERS, i))

Run the code above in your browser using DataLab