CIRCULAR SHIFT
Name:
Type:
Purpose:
Perform a circular shift of the contents of a variable in either
an up or down direction.
Description:
It is sometimes convenient to move the elements of a
variable either up or down. Given a vector of n elements,
one question is how to handle the elements when the index
is less than 1 or greater than n. For the circular shift,
elements greater than n go to the beginning of the vector
and elements less than 1 go to the end of the vector.
For example, to circular shift the contents of the variable Y
that contains 5 elements up (or right) by one element into the
output vector Y2, we mean
Y(1) => Y2(2)
Y(2) => Y2(3)
Y(3) => Y2(4)
Y(4) => Y2(5)
Y(5) => Y2(1)
To shift the contents of Y down (or left) by one element,
we mean
Y(1) => Y2(5)
Y(2) => Y2(1)
Y(3) => Y2(2)
Y(4) => Y2(3)
Y(5) => Y2(4)
The SHIFT command is similar to the CIRCULAR SHIFT, but it handles
the end points differently.
Syntax:
LET <y> = CIRCULAR SHIFT <x> <nshift>
where <x> is a response variable;
<nshift> is a number or parameter that specifies how
how many elements to shift;
and <y> is a variable that contains
the shifted values.
The sign of NSHIFT specifies the direction. If NSHIFT is
negative, the shift is down (or left) and if NSHIFT is positive
the shift is up (or right). If NSHIFT is zero, then Y = X.
Examples:
LET Y = CIRCULAR SHIFT X NSHIFT
Default:
Synonyms:
Related Commands:
SHIFT
|
= Perform a shift of a variable.
|
SCATTER
|
= Save data from a variable to specified rows of another
variable based on an index variable.
|
SEQUENCE
|
= Generate a patterned sequence of values.
|
SORT
|
= Sort a column of numbers.
|
RANK
|
= Rank a column of numbers.
|
CODE
|
= Code a column of numbers.
|
SUBSET
|
= Specifies a subset to be included in a plot, analysis,
or LET command.
|
RETAIN
|
= Retain specified rows or a subset of a variable.
|
Applications:
Implementation Date:
Program:
let y = normal random numbers for i = 1 1 10
let nshift = 3
let y2 = circular shift y nshift
let nshift = -3
let y3 = circular shift y nshift
set write decimals 3
print y y2 y3
The following output is generated:
Date created: 6/19/2009
Last updated: 6/19/2009
Please email comments on this WWW page to
[email protected].
|