This function "shifts" the values of a vector by a specified amount. For instance, if you are starting with a vector, "x", where the range of values is between 1 and 10, and you want 10 to be replaced by 9, 9 to be replaced by 8, and so on, with 1 being ultimately replaced by 10, this funciton should be of use.

shifter(x = 1:10, n = 1)

Arguments

x

The range that you are shifting

n

How much of a shift you want

Value

A vector of shifted values

References

http://stackoverflow.com/a/20825012/1270695

Author

Ananda Mahto

Examples

set.seed(1) X <- sample(10, 20, replace = TRUE) X
#> [1] 9 4 7 1 2 7 2 3 1 5 5 10 6 10 7 9 5 5 9 9
shifter()[X]
#> [1] 10 5 8 2 3 8 3 4 2 6 6 1 7 1 8 10 6 6 10 10
shifter(n = -2)[X]
#> [1] 7 2 5 9 10 5 10 1 9 3 3 8 4 8 5 7 3 3 7 7