Dataplot Vol 2 Vol 1

# GATHER

Name:
GATHER (LET)
Type:
Let Subcommand
Purpose:
Extract rows of a variable based on index values contained in another variable.
Description:
It is sometimes convenient to extract specific rows of a variable. Although this can usually be accomplished using SUBSET/EXCEPT/FOR clauses, the GATHER command can sometimes be more convenient. This is particularly true if the desired rows do not follow a regular pattern. Also, if you are going to perform an extensive set of operations on the subset of the data, it may be more convenient to use the GATHER command than to use the SUBSET command on many subsequent commands.

With the GATHER command, we define a separate variable that contains the specific rows we want to extract.

If you modify the extracted data and want to save these modified values back to the original variable, you can use the SCATTER command. Enter HELP SCATTER for further information.

Syntax:
LET <y> = GATHER <x> <index>
where <x> is a response variable;
<index> is a variable containing row numbers;
and <y> is a variable (of length equal to <index>) that contains the rows of <x> corresponding to <index>.
Examples:
LET Y = GATHER X INDEX
Default:
None
Synonyms:
None
Related Commands:
 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:
2008/11
Program:

let n = 30
let xseq = sequence 1 1 n
let x = normal rand numb for i = 1 1 n
let iindex = data 10  14  8  23  19
.
let y = gather x iindex
set write decimals 3
print xseq x iindex y

The following output is generated.
1.000         -1.073         10.000          0.270
2.000          0.573         14.000         -0.841
3.000         -0.873          8.000          0.032
4.000          0.234         23.000         -1.063
5.000         -0.455         19.000          0.034
6.000         -0.525          0.000          0.000
7.000         -0.706          0.000          0.000
8.000          0.032          0.000          0.000
9.000          1.191          0.000          0.000
10.000          0.270          0.000          0.000
11.000         -0.149          0.000          0.000
12.000         -0.197          0.000          0.000
13.000         -0.243          0.000          0.000
14.000         -0.841          0.000          0.000
15.000         -0.104          0.000          0.000
16.000          0.419          0.000          0.000
17.000          0.264          0.000          0.000
18.000          0.898          0.000          0.000
19.000          0.034          0.000          0.000
20.000          1.588          0.000          0.000
21.000          0.389          0.000          0.000
22.000         -0.470          0.000          0.000
23.000         -1.063          0.000          0.000
24.000         -0.027          0.000          0.000
25.000         -0.464          0.000          0.000
26.000          0.592          0.000          0.000
27.000         -0.506          0.000          0.000
28.000         -0.360          0.000          0.000
29.000          0.499          0.000          0.000
30.000          0.243          0.000          0.000

Date created: 12/4/2008
Last updated: 12/4/2008