SED navigation bar go to SED home page go to Dataplot home page go to NIST home page SED Home Page SED Staff SED Projects SED Products and Publications Search SED Pages
Dataplot Vol 2 Vol 1

REPLACE

Name:
    REPLACE (LET)
Type:
    Let Subcommand
Purpose:
    Match two columns (typically group-id vaues) and use the indices of any matching rows to replace the values in one array with the values in another array.
Description:
    Given the command

      LET Y2 = REPLACE GROUPID GROUP2 Y1

    Dataplot does the following:

    1. It matches the values in GROUP2 against GROUPID and returns the indices of the matching rows for the GROUPID array.

    2. The indices are used to access the corresponding value in the Y1 array.

    3. The corresponding row of Y2 is replaced with the Y1 value.

    The motivation for adding this command was to address the problem where you have two sets of labs (each data set contains a lab-id and a corresponding measurement) and you need to create a new data set that contains the data for the labs that are common to both sets. The program example below demonstrates how the REPLACE command can help accomplish this.

Syntax 1:
    LET <y2> = REPLACE <groupid> <group2> <y1>
                            <SUBSET/EXCEPT/FOR qualification>
    where <groupid> is a variable (typically a group-id variable);
                <group2> is a variable (typically a group-id variable);
                <y1> is a variable containing the values to be extracted;
                <y2> is a variable where the extracted values from <y1> are placed;
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.

    The <groupid> and <group2> variable do not need to be the same length. The <y2> variable should be a previously existing variable.

Syntax 2:
    LET <y2> = REPLACE <groupid> <group2>
                            <SUBSET/EXCEPT/FOR qualification>
    where <groupid> is a variable (typically a group-id variable);
                <group2> is a variable (typically a group-id variable);
                <y2> is the returned variable;
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.

    This is an abbreviated syntax where the <y1> variable is assummed to be all 1's.

    The <groupid> and <group2> variable do not need to be the same length. The <y2> variable should be a previously existing variable.

Examples:
    LET Y2 = REPLACE LAB1 LAB2 Y1
    LET Y2 = REPLACE LAB1 LAB2
    LET Y2 = REPLACE LAB1 LAB2 Y1 SUBSET LAB1 > 2
Default:
    None
Synonyms:
    None
Related Commands:
    MATCH = Compare two column of numbers and return the indices of any matching values.
    SORT = Sort a column of numbers.
    RANK = Rank a column of numbers.
    CODE = Code a column of numbers.
Applications:
    Data Transformation
Implementation Date:
    2006/3
Program:
     
    .  Problem:
    .
    .  We have 2 sets of labs and we want to create a new
    .  data set that contains the labs common to both sets
    .  (for each set, there is a lab-id and a measurement).
    .
    .  Step 1: Create some data
    .
    let lab1 = data 1 3 4  5 7 8 11 13 15 16 18 19
    let n1 = size lab1
    let y1 = norm rand numb for i = 1 1 n1
    .
    let lab2 = data 1 2 5 6 8 12 15 18 20
    let n2 = size lab2
    let y2 = norm rand numb for i = 1 1 n2
    .
    .  Step 2: Identify the common labs
    .
    let labint = set intersection lab1 lab2
    .
    .  Step 3: Create the tag variables for
    .          each lab
    .
    let tag1 = 0 for i = 1 1 n1
    let tag1 = replace lab1 labint
    .
    let tag3 = 0 for i = 1 1 n2
    let tag3 = replace lab2 labint
    .
    .  Step 5: Retain the common labs
    .
    set write decimals 2
    retain y1 lab1 subset tag1 = 1
    retain y2 lab2 subset tag3 = 1
    print lab1 y1 y2
        
    The following output is generated:
     
           1.00          -1.07          -0.10
           5.00           0.23           0.26
           8.00          -0.53           0.03
          15.00           1.19           0.39
          18.00          -0.15          -0.47
        

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