Highlighted
Community Trekker

## How to graph the last N values of a column?

Hi All,

I'm still relatively new to JSL, so building my script codes as I move along.

I'm trying to add to a control chart window the graph of the last 25 data points in a column of M values, e.g. colum(M-25) to (M).

I'm thinking of modifying the chart builder script to do this:

``````Control Chart Builder(
Size( 534, 454 ),
Show Two Shewhart Charts( 0 ),
Show Control Panel( 0 ),
Show Limit Summaries( 0 ),
Show Capability( 0 ),
Variables( Y( :Name( "MyColumn" ) ) ),
Chart(
Points( Statistic( "Individual" ) ),
Limits( Sigma( "Moving Range" ) ),
Warnings( Test Beyond Limits( 1 ) )
),
SendToReport(
Dispatch(
{},
"graph display 1 title",
TextEditBox,
{Set Text( "Last 25 Observations" )}
),
Dispatch( {}, "MyColumn Limit Summaries", OutlineBox, {Close( 1 )} )
)
)``````

The problem I'm having is how to chose only those last N values to display (N could be 25 or 30 or 100). My experience with other programming languages like Igor or Matlab aren't translating over to JSL for how to graph just a subset of data from a column.

If possible, I'd prefer to have it plot the data vs row index, like in the control charts, and I know the Overlay plot can do that, but I also like having the Avg show up in the graph. I would prefer to NOT plot the data as a Fit Y by X.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Staff

## Re: How to graph the last N values of a column?

Here is an example with Bivariate and Big Class that could be adapted:

``````Names Default to Here( 1 );

dt = Open( "\$SAMPLE_DATA/Big Class.jmp" );

last n = 5;
n = N Row( dt );

biv = dt << Bivariate(
Y( :weight ),
X( :height ),
Where( Row() > (n - last n) )
)``````

It is simple.

Learn it once, use it forever!
11 REPLIES 11
Highlighted
Staff

## Re: How to graph the last N values of a column?

Here is an example with Bivariate and Big Class that could be adapted:

``````Names Default to Here( 1 );

dt = Open( "\$SAMPLE_DATA/Big Class.jmp" );

last n = 5;
n = N Row( dt );

biv = dt << Bivariate(
Y( :weight ),
X( :height ),
Where( Row() > (n - last n) )
)``````

It is simple.

Learn it once, use it forever!
Highlighted
Community Trekker

## Re: How to graph the last N values of a column?

Worked! Thanks.

Had to modify slightly for the specifics, but worked.

Highlighted
Community Trekker

## Re: How to graph the last N values of a column?

@markbailey Thanks for the help.

I'm now looking to try and modify that code so it graphs the last N non-zero values. I have several rows in a column that might have missing values and want to graph only those rows which have an entry. Right now, if there is only one or two rows within the past N (in my case 25) that are non-zero, then it only graphs those one or two rows.

Your help/fedback is greatly appreciated. Thanks!

Highlighted
Super User

## Re: How to graph the last N values of a column?

Here is a simple modification to the script that @markbailey wrote, that finds the row that has the last x number of nonzero values

``````Names Default To Here( 1 );

dt = Open( "\$SAMPLE_DATA/Big Class.jmp" );
dt:weight[38] = 0;

last n = 0;

For( i = N Rows( dt ), i >= 1, i--,
If( :weight[i] > 0, last n++ );
If( last n == 5, Break() );
);
last n = N Row( dt ) - i;
n = N Row( dt );

biv = dt << Bivariate(
Y( :weight ),
X( :height ),
Where( Row() > (n - last n) )
);``````
Jim
Highlighted
Community Trekker

## Re: How to graph the last N values of a column?

Hi @txnelson, thanks for the suggestion. I ended up slightly changing the code so that it looked for empty entries rather than just non-zero entries. Your method worked and I just needed to slightly adapt it to my specific situation.

Thanks again!

``````lastNmiss = 0;

For( ii = N Rows( dt ), ii >= 1, ii--,
If( IsMissing(dt:weight[ii])!=1, lastNmiss++ );
If( lastnmiss == 8, Break() );
);
lastNmiss = N Row( dt ) - ii;
n = N Row( dt );

biv = dt << Bivariate(
Y( :weight ),
X( :height ),
Where( Row() > (n - lastnmiss) )
);``````
Highlighted
Community Trekker

## Re: How to graph the last N values of a column?

Hello Sir, I want to draw chart of a given big data set. But i need to check one particular column satisfies if condition and then consider corresponding rows for plotting graph. I would like to do this through jsl script. Could you help me as am very beginner. Thanks!
Highlighted
Community Trekker

## Re: How to graph the last N values of a column?

How to graph data from the data table with one particular column satisfies given if condition?
Highlighted
Staff

## Re: How to graph the last N values of a column?

This seems to be a different question from the topic of the thread, but maybe try something like this:

``````Names DefaultToHere(1);

// Open a table and give it a table reference ('dt')
dt = Open("\$SAMPLE_DATA/Big Class.jmp");

// Get a list of all the columns in the table
cols = dt << getColumnNames("String");

// Define any logical condition that identifies one or more columns by its name
targetCols = {};
for(c=1, c<=NItems(cols), c++, if(Contains(cols[c], "gh"), InsertInto(targetCols, cols[c])));

// Make a plot using'taregtCols' as the y variables
biv = dt << OneWay(X(:sex), Y(Eval(targetCols)));``````
Highlighted
Community Trekker

## Re: How to graph the last N values of a column?

Thanks! Not sure i submitted my question correctly. I want to draw chart of a given big data set. But i need to check one particular column satisfies if condition and then if condition is satisfied then consider corresponding rows for plotting graph. I would like to do this through jsl script. Could you help me as am very beginner. Thanks!