cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.
  • JMP will suspend normal business operations for our Rest and Recharge Day on Friday, October 2, 2026.
    Regular business hours will resume on Monday, October 5, 2026.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
zhouye0
Level II

Calculating mean for a set of columns in jsl

I have a set of column names in a list called list_1, now I want to calculate the mean for each column, but the thing is I do not want to include all the rows in the column when calculating the mean, i have another pre-defined variable that selects specific rows. How do I calculate the mean of the column by selecting the specified rows instead of stepping down through all the rows?

for example i want the mean to be calculated based on rows 1,3,4,5,9 on a specific column

dt << current data table;

for (p=1,p<=nitems(list_1), p++,

  col = list_1

;

mean = col mean(dt :col );

)

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: Calculating mean for a set of columns in jsl

The col functions appear to ignore the excluded row state.  This works however:

//for example i want the mean to be calculated based on rows 1,3,4,5,9 on a specific column

dt = New Table( "testmean", Add Rows( 10 ),

      New Column( "C1", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ) ),

      New Column( "C2", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [5, 4, 3, 6, 7, 2, 3, 6, 5, 4] ) )

);

sel_rows = [1,3,4,5,9];

list_1 = {"C1", "C2"};

for (p=1, p <= nitems(list_1), p++,

      one_col = list_1[p];

      mean = mean(column(dt, one_col )[sel_rows]);

      show(p, mean);

);

View solution in original post

1 REPLY 1
pmroz
Super User

Re: Calculating mean for a set of columns in jsl

The col functions appear to ignore the excluded row state.  This works however:

//for example i want the mean to be calculated based on rows 1,3,4,5,9 on a specific column

dt = New Table( "testmean", Add Rows( 10 ),

      New Column( "C1", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ) ),

      New Column( "C2", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [5, 4, 3, 6, 7, 2, 3, 6, 5, 4] ) )

);

sel_rows = [1,3,4,5,9];

list_1 = {"C1", "C2"};

for (p=1, p <= nitems(list_1), p++,

      one_col = list_1[p];

      mean = mean(column(dt, one_col )[sel_rows]);

      show(p, mean);

);

Recommended Articles