vecShift: Shift vector values to right or left Modified from:...

Description Usage Arguments Value Examples

View source: R/vecShift.R

Description

Shift vector values to right or left Modified from: https://stackoverflow.com/a/37069049/1898713

Usage

1
vecShift(in.x, in.n, in.invert = FALSE, in.fill = NA, in.circle = F)

Arguments

in.x

Vector for which to shift values

in.n

Number of places to be shifted. Positive numbers will shift to the right by default. Negative numbers will shift to the left by default. The direction can be inverted by the invert parameter.

in.invert

Whether or not the default shift directions should be inverted.

in.fill

The value that should be inserted by default.

in.circle

If TRUE, inserted values will be taken from shifted vector

Value

Shifted vector

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
v = 1:10

# Shift by two elements right, fill with NAs
vecShift(v, 2)

# Shift by two elements right, fill with 0's
vecShift(v, 2, in.fill = 0)

# Shift by two elements left, fill circular
vecShift(v, -2, in.circle = T)

dmattek/tca-package documentation built on Dec. 10, 2019, 4:10 p.m.