rotate(x, k), x a vector or matrix, k an integer. |

rotate(x, k) "rotates" by k rows each column of the REAL, LOGICAL or CHARACTER vector or matrix x. When k > 0, rows pushed down off the end are shifted to the start and when k < 0, rows pushed up before the start are moved to the end. k must be a single integer and is interpreted modulo nrows(x). For example, rotate(x,k) and rotate(x,k %% nrows(x)) are equivalent. More explicitly, for -m < k < m, where m = nrows(x), rotate() moves rows as follows: 0 <= k <= m-1 (down column shift) -(m-1) <= k <= 0 (up column shift) Row j -> Row j+k for j=1,...,m-k Row j -> Row j+k+m for j=1,...,-k Row j -> Row j+k-m for j=m-k+1,...,m Row j -> Row j+k for j=-k+1,...,m The result has the same size and type as x. When isvector(x) is True, the result is a pure vector (ndims(x) = 1). Otherwise, the result has 2 dimensions. Examples: Cmd> rotate(vector(1,3,2,6,5,4),2) (1) 5 4 1 3 2 (6) 6 Cmd> rotate(matrix(vector(1,3,2,7, 6,5,4,8),4), -2) (1,1) 2 4 (2,1) 7 8 (3,1) 1 6 (4,1) 3 5 Cmd> rotate(vector("A","B","C","D"),-1) (1) "B" (2) "C" (3) "D" (4) "A" Caution: Do not confuse rotate() with rotation() which does rotation of factor loadings.

Gary Oehlert 2003-01-15