Dataplot Vol 2 Vol 1

# SHIFT

Name:
SHIFT (LET)
Type:
Let Subcommand
Purpose:
Shift the contents of a variable either up or down.
Description:
It is sometimes convenient to move the elements of a variable either up or down.

For example, to 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(6)

To shift the contents of Y down (or left) by one element, we mean

Y(2) => Y2(1)
Y(3) => Y2(2)
Y(4) => Y2(3)
Y(5) => Y2(4)

One question is how do we define the end-point values for Y2 (i.e., Y2(1) for the up shift and Y2(5) for the down shift)?

Dataplot handles this by first doing

Y2 = Y

for all elements. So for the up shift, Y2(1) = Y1(1) and for the down shift Y2(5) = Y(5).

Syntax:
LET <y> = 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 = SHIFT X NSHIFT
Note:
If you want to handle the end points differently, then this can usually be accomplished with FOR clause. For example, the set the end points to zero, do something like

LET NSHIFT =5
LET AVAL = 0
LET Y2 = SHIFT Y NSHIFT
LET Y2 = AVAL FOR I = 1 1 NSHIFT
Default:
None
Synonyms:
None
Related Commands:
 CIRCULAR SHIFT = Perform a circular 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:
Data Transformation
Implementation Date:
2009/2
Program:
```
let y = normal random numbers for i = 1 1 10
let nshift = 3
let y2 = shift y nshift
let nshift = -3
let y3 = shift y nshift
set write decimals 3
print y y2 y3
```
The following output is generated.
```---------------------------------------------
Y             Y2             Y3
---------------------------------------------
-1.073         -1.073          0.233
0.573          0.573         -0.455
-0.873         -0.873         -0.525
0.233         -1.073         -0.705
-0.455          0.573          0.032
-0.525         -0.873          1.190
-0.705          0.233          0.269
0.032         -0.455          0.032
1.190         -0.525          1.190
0.269         -0.705          0.269
0.000          0.032          0.000
0.000          1.190          0.000
0.000          0.269          0.000
```

Date created: 4/27/2009
Last updated: 4/27/2009
Please email comments on this WWW page to alan.heckert@nist.gov.