<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: JMP script for average column in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/618964#M81835</link>
    <description>&lt;P&gt;If the number of column is fixed, you can hard-code the &lt;STRONG&gt;means&lt;/STRONG&gt;,&lt;/P&gt;&lt;P&gt;if the "etc." is variable, you probably need some &lt;STRONG&gt;Insert Into&lt;/STRONG&gt; and &lt;STRONG&gt;Eval(Substitute()):&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Semiconductor Capability.jmp" );
offset = 5;
nc = N Col( dt );
length = 10;
groups = Floor((nc - offset) / length);
For( group = 1, group &amp;lt;= groups, group++,
	myFormula = Expr( Mean() );
	For( i = 1, i &amp;lt;= length, i++,
		Insert Into( myFormula, NameExpr(As Column( offset + (group-1)*length +i ) ))
	);
	myName = "average" || Char( group );
	Eval(Substitute(Expr(new Column(__myName__,Formula(__myFormula__))),Expr(__myFormula__),NameExpr(myFormula),Expr(__myName__),NameExpr(myName) ));
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 01 Apr 2023 06:49:59 GMT</pubDate>
    <dc:creator>hogi</dc:creator>
    <dc:date>2023-04-01T06:49:59Z</dc:date>
    <item>
      <title>JMP script for average column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/618935#M81831</link>
      <description>&lt;P&gt;I've a VERY novice JMP script writer trying to write a command to average a set of columns into a new column with the averages. &amp;nbsp;This is equivalent to highlighting the columns, then selecting New Formula Column &amp;gt; Combine &amp;gt; Average. &amp;nbsp;However, I can't find anything in the script library or online that lets me do this. &amp;nbsp;Anyone have any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To add an additional complication, I want the script to take columns 2-11, 12-21, 22-31, etc. and average each column group. &amp;nbsp;The columns do not have set names, so I can't just put the column names into the script (it's not possible to make the names consistent because the column names are sample names and I need to keep them that way). &amp;nbsp;The number of column groups in each JMP file is not consistent because the number of samples in each JMP file can vary widely. &amp;nbsp;Is there a simple way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using JMP 17.0.0 on a Mac if that's helpful. &amp;nbsp;Any help is appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:59:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/618935#M81831</guid>
      <dc:creator>hsjoyner</dc:creator>
      <dc:date>2023-06-10T23:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: JMP script for average column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/618941#M81832</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/47394"&gt;@hsjoyner&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have you investigated the column() function? Instead of using a column name, you can use it's index.&amp;nbsp; This could be useful in a for() loop.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="StarfruitBob_0-1680303365358.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/51663iC5B45D0298607E41/image-size/medium?v=v2&amp;amp;px=400" role="button" title="StarfruitBob_0-1680303365358.png" alt="StarfruitBob_0-1680303365358.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 22:56:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/618941#M81832</guid>
      <dc:creator>StarfruitBob</dc:creator>
      <dc:date>2023-03-31T22:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: JMP script for average column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/618964#M81835</link>
      <description>&lt;P&gt;If the number of column is fixed, you can hard-code the &lt;STRONG&gt;means&lt;/STRONG&gt;,&lt;/P&gt;&lt;P&gt;if the "etc." is variable, you probably need some &lt;STRONG&gt;Insert Into&lt;/STRONG&gt; and &lt;STRONG&gt;Eval(Substitute()):&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Semiconductor Capability.jmp" );
offset = 5;
nc = N Col( dt );
length = 10;
groups = Floor((nc - offset) / length);
For( group = 1, group &amp;lt;= groups, group++,
	myFormula = Expr( Mean() );
	For( i = 1, i &amp;lt;= length, i++,
		Insert Into( myFormula, NameExpr(As Column( offset + (group-1)*length +i ) ))
	);
	myName = "average" || Char( group );
	Eval(Substitute(Expr(new Column(__myName__,Formula(__myFormula__))),Expr(__myFormula__),NameExpr(myFormula),Expr(__myName__),NameExpr(myName) ));
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 01 Apr 2023 06:49:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/618964#M81835</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-04-01T06:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: JMP script for average column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/618968#M81836</link>
      <description>&lt;P&gt;Here is a script that I hope creates what you are looking for.&amp;nbsp; It creates new columns that average groups of 10 columns for an undetermined number of columns.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1680334635093.png" style="width: 881px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/51664i6B5A6C90253D7305/image-dimensions/881x414?v=v2" width="881" height="414" role="button" title="txnelson_0-1680334635093.png" alt="txnelson_0-1680334635093.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

// Create an example data table to use for illustration of how to 
// create the sets of average columns
dt  =
// Open Data Table: semiconductor capability.jmp
// → Data Table( "semiconductor capability" )
Open( "$SAMPLE_DATA/semiconductor capability.jmp" );

// Delete the first 3 columns to match the description
// of the suggested data table structure
dt &amp;lt;&amp;lt; delete columns({"lot_id","wafer","wafer ID in lot ID"});

// Create new columns that have the groups of 10 columns
startingNCol = N Cols(dt);
start = 2;
groupSize = 10;
while(start+groupSize&amp;lt;=startingNCol,
	eval(substitute(expr(
		dt &amp;lt;&amp;lt; New Column("Average " || char( start ) || "-" || char(start + groupSize),
			set each value(Mean(current data table()[row(),index(theStart,theEnd)])));
		),
		expr(theStart), start, expr(theEnd), start+groupSize
	));
	start=start+groupSize;
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Apr 2023 07:38:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/618968#M81836</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-04-01T07:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: JMP script for average column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/618973#M81837</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Mean(current data table()[row(),index(theStart,theEnd)])&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;wow, very elegant - much nicer than filling the mean manually with the column references!&lt;/P&gt;</description>
      <pubDate>Sat, 01 Apr 2023 11:13:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/618973#M81837</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-04-01T11:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: JMP script for average column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/894322#M105504</link>
      <description>&lt;P&gt;Why does the formula column fail to produce the same same values as in column Average 2 - 12?&lt;/P&gt;
&lt;P&gt;Mean( :NPN1, :PNP1, :PNP2, :NPN2, :PNP3, :IVP1, :PNP4, :NPN3, :IVP2, :NPN4, :SIT1 )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: I was distracted when writing the comment and the above formula produces a matching value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Follow-up: Mean() seems very sensitive to column Format properties, as I got different results in my own data table when columns were set to Fixed Dec Width 15 Dec 3 versus Best Width 12. Any recommendations on avoiding this issue?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Aug 2025 21:25:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/894322#M105504</guid>
      <dc:creator>Luis_HC</dc:creator>
      <dc:date>2025-08-13T21:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: JMP script for average column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/894323#M105505</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/47394"&gt;@hsjoyner&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;If I'm understanding correctly, and as long as you want the mean for all groups of columns, you should be able to grab a list of the column groups in the table, and then loop through those group names to make formula columns that dynamically pull the columns in each group. Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
groupNames = dt &amp;lt;&amp;lt; get column groups names;
For Each( {groupName, index}, groupNames, 
	Eval(
		Eval Expr(
			dt &amp;lt;&amp;lt; New Column( groupName || " Mean",
				Formula( Mean( Current Data Table() &amp;lt;&amp;lt; get column group( Expr( groupName ) ) ) )
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps!&lt;/P&gt;
&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2026"&gt;@jules&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;edit: after rereading your message and the replies I've realized you are talking about groups of columns (as in, sets of columns) rather than columns that are in actual groups in the table. So, this answer won't be helpful for you, but I'll leave it here in case someone finds themselves in that situation! :grinning_face:&lt;/img&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2025 00:00:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-script-for-average-column/m-p/894323#M105505</guid>
      <dc:creator>jules</dc:creator>
      <dc:date>2025-08-14T00:00:59Z</dc:date>
    </item>
  </channel>
</rss>

