cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

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