Col Standardize
Col Standardize using For
Example 1
Summary: Generates a customized data table by matching values from a specified list and inserting corresponding data into an empty list.
Code:
dt = Open("data_table.jmp");
xlist = {"1", "2", "3", "4"};
testVar = {};
For( i = 1, i <= N Items( xlist ), i++,
y = "sex";
If( i == 3,
y = "height";
Row() = 1;
);
Match( xlist[i],
xlist[1], Insert Into( testVar, Eval List( {i, y} ) ),
xlist[2], Insert Into( testVar, Eval List( {i, y} ) ),
xlist[3], Insert Into( testVar, Eval List( {i, y, Round( Col Standardize( Column( dt, y ) ), 3 )} ) ),
xlist[4], Insert Into( testVar, Eval List( {i, y} ) ),
Insert Into( testVar, Eval List( {i, y, "error"} ) )
);
);
Code Explanation:
- Open data table;
- Initialize xlist with four strings.
- Initialize empty list testVar.
- Start loop with i from 1 to 4.
- Set y to "sex".
- If i is 3, set y to "height" and reset row to 1.
- Match xlist[i] value.
- Insert {i, y} into testVar for first two matches.
- For third match, insert {i, y, standardized height rounded to 3}.
- Insert {i, y} into testVar for fourth match.
Example 2
Summary: Generates a distribution analysis for continuous variables in a specified data table using MatchMZ and conditional logic.
Code:
dt = Open("data_table.jmp");
xlist = {"1", "2", "3", "4"};
testVar = {};
For( i = 1, i <= N Items( xlist ), i++,
y = "sex";
If( i == 3,
y = "height";
Row() = 1;
);
MatchMZ( xlist[i],
xlist[1], Insert Into( testVar, Eval List( {i, y} ) ),
xlist[2], Insert Into( testVar, Eval List( {i, y} ) ),
xlist[3], Insert Into( testVar, Eval List( {i, y, Round( Col Standardize( Column( dt, y ) ), 3 )} ) ),
xlist[4], Insert Into( testVar, Eval List( {i, y} ) ),
Insert Into( testVar, Eval List( {i, y, "error"} ) )
);
);
Code Explanation:
- Open data_table data
- Define xlist with values.
- Initialize empty testVar list.
- Start loop over xlist items.
- Set y variable to "sex".
- Change y to "height" for third iteration.
- Reset row to 1 if y changed.
- Use MatchMZ for conditional logic.
- Insert {i, y} into testVar for first two xlist items.
- Insert {i, y, standardized height} for third item.
- Insert {i, y} into testVar for fourth item.
- Handle any unmatched cases with error message.
Example 3
Summary: Generates a list containing variables and their corresponding values from a specified data table, utilizing a For loop and MatchV3 function.
Code:
dt = Open("data_table.jmp");
xlist = {"1", "2", "3", "4"};
testVar = {};
For( i = 1, i <= N Items( xlist ), i++,
y = "sex";
If( i == 3,
y = "height";
Row() = 1;
);
MatchV3( xlist[i],
xlist[1], Insert Into( testVar, Eval List( {i, y} ) ),
xlist[2], Insert Into( testVar, Eval List( {i, y} ) ),
xlist[3], Insert Into( testVar, Eval List( {i, y, Round( Col Standardize( Column( dt, y ) ), 3 )} ) ),
xlist[4], Insert Into( testVar, Eval List( {i, y} ) ),
Insert Into( testVar, Eval List( {i, y, "error"} ) )
);
);
Code Explanation:
- Open data table.
- Define variable
xlist. - Initialize empty list
testVar. - Start loop over
xlist. - Set default variable
yto "sex". - Change
yto "height" on third iteration. - Reset row index to 1 on third iteration.
- Match value in
xlist. - Insert evaluated list into
testVar. - End loop.