Learn R Programming

taRifx (version 1.0.6.2)

shift: Shifts a vector's elements left or right by N elements.

Description

Shifts a vector's elements left or right by N elements.

Usage

shift(x, ...)

# S3 method for default shift (x, n = 1, wrap = TRUE, pad = FALSE, ...)

# S3 method for data.frame shift (x, ...)

Arguments

x

A vector to be operated on

n

Number of rows to shift by (if negative, shift to right instead of left)

wrap

Whether to wrap elements or not (adds the entry at the beginning to the end)

pad

Whether to pad with NAs or not. pad does nothing unless wrap is false, in which case it specifies whether to pad with NAs

Other items to pass along

Value

vector of the same type as vec

Examples

Run this code
# NOT RUN {
test <- seq(10)
shift(test)
# }

Run the code above in your browser using DataLab