shiftData: Shift Data

Description Usage Arguments Value See Also Examples

View source: R/shiftData.R

Description

Returns a vector like the input, but with the position of the data shifted up or down.

Usage

1
shiftData(x, k = 1, fill = NA, circular = FALSE)

Arguments

x

any vector.

k

a positive or negative whole number of positions to shift the data. Positive values shift data to a higher position and negative values shift data to a lower position.

fill

a scalar value like x used to fill in the first k positions or the last -k positions if circular=FALSE. Ignored if circular=TRUE. The default value is NA. If x is class "factor," then fill must be NA or a valid level in x.

circular

logical (TRUE or FALSE). If TRUE, then treat x as a circular buffer, rotating values from the end into the beginning if k is positive and vice versa if k is negative. If FALSE, then use the value of fill. The default value is FALSE.

Value

A vector like x, with data shifted in position.

See Also

lag

Examples

1
2
3
4
shiftData(1:5, k=1)
# [1] NA  1  2  3  4
shiftData(1:5, k=1, circ=TRUE)
# [1] 5 1 2 3 4

smwesten-usgs/recharge documentation built on March 8, 2021, 11:51 a.m.