- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Data Filter stopped in a for-loop
I am writing a for-loop script to search for the x-values of the y-maximum peaks in some parts of the spectra collected in different experimental conditions. However, the Data Filter stopped after running one round by the warning "Your selection was changed in another window." How can I get rid of this warning so that the script can be run smoothly to complete the for-loop?
Let me use Big Class.jmp example to demonstrate the problem. The objective is to show the subset of data corresponding to the people having the maximum weight (y-maximum value) in several ranges of heights (x-value ranges, say 55-60, 60-62, 62-65) by different ages (similar to experimental conditions).
The x-value ranges are grouped by two lists, one containing the lower limits & another one the upper limits. The maximum is found by Col Maximum with Data Filter. The calculation is looped for several x-value ranges along the lists. However, after running for i=1, the loop stops and the Data Filter warning appears. How to get rid of it to let the script complete the for-loop?
Names Default To Here( 1 );
ListA = {55, 60, 62};
ListB = {60, 62, 65};
for(i=1, i<=3, i++,
dt = Data Table( "Big Class" );
Current Data Table (dt);
a = ListA[i];
b = ListB[i];
dt << Data Filter(Add Filter(columns(:height), where(:height > a & :height < b)), Mode( Select( 0 ), Show( 0 ), Include( 1 )), Show Window(0), Auto Clear(1));
dt << select where (col maximum(:weight, :age, Excluded()) == :weight & :height > a & :height < b);
dt << subset(selected rows(1), columns({"name", "age", "sex", "height", "weight"}));
dt << Clear Row States;
dt << Clear Select();
);
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Data Filter stopped in a for-loop
Please have a look at the documentation of Col Max - actually it can do all the job that is needed.
Just use an auxiliary column height_bin (e.g. via Transform Column). No need for a data filter ...
according to this table, it's James, Barbara, Judy and Marion.
If you want to define the the height_bins via a Data Filter, make sure that you don't miss the junction points, e.g. height=60.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column( "height_bin",
"Character",
Formula(
If(
:height < 60, "<60",
:height <62, "<62",
">=62"
)
) );
New Column( "weight_max",
Formula( Col Maximum( :weight, :age, :height_bin ) )
);
New Column( "is max",nominal,
Formula( :weight == :weight_max ),
);
Graph Builder(
Variables( X( :age ), Y( :weight ), Group Y( :height_bin ) ),
Elements( Bar( X, Y, Label( "Label by Row" ) ) ),
Local Data Filter( Add Filter( columns( :is max ), Where( :is max == 1 ) ) )
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Data Filter stopped in a for-loop
I believe the simplified JSL below gives you what you want.
Names Default To Here( 1 );
dt =
// Open Data Table: semiconductor capability.jmp
// → Data Table( "semiconductor capability" )
Open( "$SAMPLE_DATA/big class.jmp" );
ListA = {55, 60, 62};
ListB = {60, 62, 65};
For( i = 1, i <= 3, i++,
a = ListA[i];
b = ListB[i];
Current Data Table( dt );
theMax = Col Maximum( If( :weight & :height > a & :height < b, :weight, . ) );
dt << select where( theMax == :weight & :height > a & :height < b );
If( N Rows( dt << get selected rows ) > 0,
dt << subset( selected rows( 1 ), columns( {"name", "age", "sex", "height", "weight"} ) )
);
dt << Clear Row States;
Wait( 0 );
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Data Filter stopped in a for-loop
However, this script does not have the "by age" function. For example, in my script, when i = 2 (ListA = 60, ListB = 62), the result is
Name | Age | Sex | Height | Weight |
JAMES | 12 | M | 61 | 128 |
ALICE | 13 | F | 61 | 107 |
JUDY | 14 | F | 61 | 81 |
However, your script gives the corresponding part as
Name | Age | Sex | Height | Weight |
JAMES | 12 | M | 61 | 128 |
This is because my script has the "by age" part in Col Maximum. Unfortunately, even if I add "by age" part in your script:
theMax = Col Maximum( If( :weight & :height > a & :height < b, :weight, . ), :age );
An alert appears: "Invalid Row Number"
Your script runs smoothly. How can we add the "by age" part in Col Maximum in your script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Data Filter stopped in a for-loop
Please have a look at the documentation of Col Max - actually it can do all the job that is needed.
Just use an auxiliary column height_bin (e.g. via Transform Column). No need for a data filter ...
according to this table, it's James, Barbara, Judy and Marion.
If you want to define the the height_bins via a Data Filter, make sure that you don't miss the junction points, e.g. height=60.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column( "height_bin",
"Character",
Formula(
If(
:height < 60, "<60",
:height <62, "<62",
">=62"
)
) );
New Column( "weight_max",
Formula( Col Maximum( :weight, :age, :height_bin ) )
);
New Column( "is max",nominal,
Formula( :weight == :weight_max ),
);
Graph Builder(
Variables( X( :age ), Y( :weight ), Group Y( :height_bin ) ),
Elements( Bar( X, Y, Label( "Label by Row" ) ) ),
Local Data Filter( Add Filter( columns( :is max ), Where( :is max == 1 ) ) )
);