R: Shift Vector Left/Right

shift {qdapTools} | R Documentation

## 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)

### 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.

### Value

Returns a shifted vector.

### Examples

    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))

[Package qdapTools version 1.3.3 Index]