| VecRot {DescTools} | R Documentation |
Shift the elements of a vector in circular mode to the right or to the left by k elements, such that the kth element is the first one of the new vector and the first k-1 elements are appended to the end.
VecShift does not attach the superfluous elements on one side to the other, but fills the resulting gaps with NAs.
VecRot(x, k = 1) VecShift(x, k = 1)
x |
a vector of any type. |
k |
the number of elements to shift. |
The function will repeat the vector two times and select the appropriate number of elements from the required shift on.
the shifted vector in the same dimensions as x.
Andri Signorell <andri@signorell.net>
VecRot(c(1,1,0,0,3,4,8), 3) VecRot(letters[1:10], 3) VecRot(letters[1:10], -3) VecShift(letters[1:10], 3) VecShift(letters[1:10], -3)