For
Example 1
Summary: Opens a data table, loops through the first 49 rows, and sets the row state to selected for each iteration.
Code:
Open("data_table.jmp");
For( i = 1, i < 50, i++,
Row State( i ) = Selected State( 1 )
);
Code Explanation:
- Open data table.
- Loop from 1 to 49.
- Set row state to selected for each iteration.
Example 2
Summary: Runs the initialization of a data table by setting the sex column values to empty strings for the first 8 rows.
Code:
Open("data_table.jmp");
For( i = 1, i <= 8, i++, :sex[i] = "" );
Code Explanation:
- Open data table;
- Loop through first 8 rows.
- Set sex column values to empty string.
Example 3
Summary: Selects rows in a data table, setting their selected state to 0 for rows 1 through 49.
Code:
Open("data_table.jmp");
For( i = 1, i < 50, i++,
Row State( i ) = Selected State( 0 )
);
Code Explanation:
- Open data table.
- Start loop from row 1.
- Iterate through rows 1 to 49.
- Set selected state of each row to 0.
- End loop.
Example 4
Summary: Excludes rows from a data table based on specific conditions, utilizing a For loop and row selection.
Code:
dt = Open("data_table.jmp");
myRows = dt << get rows where( :age == 12 & :sex == "M" );
For( i = 1, i <= N Items( myRows ), i++,
:height[myRows[i]] = .
);
myRows = dt << select where( :age == 12 & :sex == "F" );
dt << exclude;
Code Explanation:
- Open data table.
- Get rows where age is 12 and sex is M.
- Loop through selected rows.
- Set height to missing for each row.
- Select rows where age is 12 and sex is F.
- Exclude selected rows.
Example 5
Summary: Runs the initialization of a data table by setting age values to missing for the first 9 rows.
Code:
Open("data_table.jmp");
For( myRow = 1, myRow <= 9, myRow++,
:age[myRow] = .
);
Code Explanation:
- Open data table;
- Loop through first 9 rows.
- Set age values to missing.
Example 6
Summary: Process of setting age values to missing for rows where age is 12 in a specified data table.
Code:
dt = Open("data_table.jmp");
myRows = dt << get rows where( :age == 12 );
For( i = 1, i <= N Items( myRows ), i++,
:age[myRows[i]] = .
);
Code Explanation:
- Open data table;
- Get rows where age is 12.
- Loop through selected rows.
- Set age values to missing.
Example 7
Summary: Filters and modifies data in a JMP data table by selecting rows where age is 12 and sex is 'F', then setting age values to missing.
Code:
dt = Open("data_table.jmp");
myrows = dt << get rows where( :age == 12 & :sex == "F" );
For( i = 1, i <= N Items( myrows ), i++,
:age[myrows[i]] = .
);
Code Explanation:
- Open data table.
- Get rows where age is 12.
- Filter for female gender.
- Loop through selected rows.
- Set age values to missing.
Example 8
Summary: Generates random numbers for reliability forecasting in a specified data table, utilizing the Run Script platform.
Code:
dt = Open("data_table.jmp");
ran = [];
For( i = 1, i <= 2, i++,
obj = dt << Run Script( "Reliability Forecast" );
option = obj << Forecast Options;
option << Random Seed( 1111 );
ran = ran |/ (Random Uniform());
);
Code Explanation:
- Open table.
- Initialize empty list.
- Start loop 2 times.
- Run reliability forecast script.
- Access forecast options.
- Set random seed.
- Generate random number.
- Append to list.
- End loop.
- Save results.
Example 9
Summary: Runs the random selection and modification of cells in a specified data table, utilizing a For loop to iterate through rows and columns.
Code:
dt = Open("data_table.jmp");
For( j = 1, j <= 3, j++,
rand_row = Random Integer( 1, N Row( dt ) );
rand_col = Random Integer( 1, N Col( dt ) - 1 );
dt[rand_row, rand_col] = .;
);
Code Explanation:
- Open data table;
- Initialize loop counter j to 1.
- Check if j is less than or equal to 3.
- Generate random row index.
- Generate random column index.
- Set selected cell to missing value.
- Increment j by 1.
- Repeat steps 3-7 until j > 3.
For using Get Rows Where
Summary: Selects specific rows in a data table, opening and retrieving all rows before selecting first 12 and then rows 33 to 40.
Code:
dt = Open("data_table.jmp");
dt << Get Rows Where();
For( i = 1, i <= 12, i++,
Selected( Row State( i ) ) = 1
);
For( i = 33, i <= 40, i++,
Selected( Row State( i ) ) = 1
);
Code Explanation:
- Open data table.
- Retrieve all rows.
- Select first 12 rows.
- Select rows 33 to 40.
For using Random Reset
Summary: Generates a data table with random values and then runs a SEM script to perform multiple group analysis, capturing the log output.
Code:
dt = Open("data_table.jmp");
Random Reset( 123 );
For( i = 1, i <= 30, i++,
row = Random Index( 100, 1 );
col = Random Index( 7, 1 );
dt[row, col] = .;
);
dt[1, 2] = 3;
dt[2, 2] = 3;
dt[3, 2] = 3;
dt[4, 2] = 3;
dt[5, 2] = 3;
dt[1, 3 :: 7] = .;
dt[2, 3 :: 7] = .;
dt[3, 3 :: 7] = .;
dt[4, 3 :: 7] = .;
dt[5, 3 :: 7] = .;
log = Log Capture( obj = dt << Run Script( "SEM: Multiple Group Analysis LGC" ) );
Code Explanation:
- Open data table;
- Set random seed to 123.
- Loop 30 times.
- Randomly select row and column.
- Set selected cell to missing.
- Set first five cells in second column to 3.
- Set first five cells in columns 3 to 7 to missing.
- Capture log from running SEM script.
For using N Row
Summary: Runs the processing and validation of data table columns, selecting specific rows based on conditions and combining variables into a matrix.
Code:
dt = Open("data_table.jmp");
X = dt << Get All Columns As Matrix;
X = X[0, 4 :: 13];
dum_var_1 = J( N Row( X ), 1, . );
For( i = 1, i <= N Row( X ), i++,
dum_var_1[i] = If( X[i, 2] == 1, 1, 0 )
);
dum_var_2 = J( N Row( X ), 1, . );
For( i = 1, i <= N Row( X ), i++,
dum_var_2[i] = If( X[i, 2] == 2, 1, 0 )
);
mat_diab = X[0, 1] || dum_var_1 || dum_var_2 || X[0, 3 :: 10];
valid = :Validation << Get Values;
train_idx = Loc( valid, 1 );
Code Explanation:
- Open data table;
- Extract all columns as matrix.
- Select specific columns for X.
- Initialize dummy variable 1.
- Loop through rows to set dummy variable 1.
- Initialize dummy variable 2.
- Loop through rows to set dummy variable 2.
- Combine variables into matrix.
- Retrieve validation column values.
- Find indices for training data.
For using Chart
Summary: Creates a line chart to visualize mean sales and assets by type, with customizable colors for each axis.
Code:
dt = Open("data_table.jmp");
obj = Chart(
X( :Type ),
Y( Mean( :Name( "Sales($M)" ) ), Mean( :Name( "Assets($Mil.)" ) ) ),
Line Chart( 1 ),
Y[1] << Overlay Color( 4 ),
Y[2] << Overlay Color( 3 )
);
rpt = obj << report;
cert rs = {1, 2, 3, 4, 5};
k = 1;
For( i = 1, i <= N Items( cert rs ), i++,
k = k + 12
);
Code Explanation:
- Open data table;
- Create chart object.
- Set X-axis to Type.
- Set Y-axis to mean Sales and Assets.
- Add line chart type.
- Color first Y-axis line blue.
- Color second Y-axis line orange.
- Generate chart report.
- Initialize certification array.
- Loop through certification array elements.
For using Text Edit Box
Summary: Creates a line chart with multiple series, utilizing text edit boxes and custom rendering styles for data visualization.
Code:
cert label = {label( "Mean(Sales($M))" ), label( "Mean(Assets($Mil.))" )};
cert text edit bx = {Text Edit Box( "Y", default font id( 9 ), wrapWidth( 277 ), justification( 1 ), vjustification( 1 ), left )};
cert title = {Title( "Type" )};
cert labels = {"Labels", Labels( "Aerospace", "Beverages", "Computer", "Drugs", "Oil", "Soap" )};
cert rs = {rs( 0, Dot, 4 ), rs( 0, Dot, 3 )};
cert pen size = {Pen Size( 1 ), Pen Size( 2 ), Pen Size( 1 ), Pen Size( 2 ), Pen Size( 1 ), Pen Size( 2 ), Pen Size( 1 ), Pen Size( 2 ),
Pen Size( 1 ), Pen Size( 2 ), Pen Size( 1 ), Pen Size( 2 ), Pen Size( 1 ), Pen Size( 2 ), Pen Size( 1 ), Pen Size( 2 ), Pen Size( 1 ),
Pen Size( 2 ), Pen Size( 1 ), Pen Size( 2 )};
cert color = {color( 3 ), color( 4 ), color( 3 ), color( 4 ), color( 81 )};
dt = Open("data_table.jmp");
obj = Chart(
X( :Type ),
Y( Mean( :Name( "Sales($M)" ) ), Mean( :Name( "Assets($Mil.)" ) ) ),
Line Chart( 1 ),
Y[1] << Overlay Color( 4 ),
Y[2] << Overlay Color( 3 )
);
rpt = obj << report;
k = 1;
For( i = 1, i <= N Items( cert rs ), i++,
k = k + 12
);
Code Explanation:
- Define labels for chart.
- Create text edit box.
- Define title for chart.
- Define labels for categories.
- Define rendering styles.
- Define pen sizes.
- Define colors.
- Open data table;
- Create line chart object.
- Extract report from chart.