<?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: How can I get the sum of all different combinations of a group of columns? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/633000#M83139</link>
    <description>&lt;P&gt;Here is the modification to the code that I previously submitted.&amp;nbsp; This code add a new column for each combination of the first 10 columns.&amp;nbsp; It adds 1013 new columns.&amp;nbsp; Please check the correctness of the additions to the data table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = data table("sum combined");

startCol = 2;
endCol = N Col( dt ) ;

colNames = dt &amp;lt;&amp;lt; get column names( string );

// Build Combinations
For( nInCombo = 2, nInCombo &amp;lt;= endCol, nInCombo++,
	combos = NChooseK Matrix( endCol, nInCombo );
	For( row = 1, row &amp;lt;= N Rows( combos ), row++,
		// create the column name and the formula for the new column
		name = "";
		cols = N Cols( combos );
		code = "Sum(  :\!"" || colNames[combos[row, 1, 1]] || "\!"n";
		name = "\!"" || colNames[combos[row, 1, 1]];
		For( col = 2, col &amp;lt;= cols, col++,
			code = code || ",  :\!"" || colNames[combos[row, col, 1]] || "\!"n";
			name = name || " + " || colNames[combos[row, col, 1]];
		);
		name = name || "\!"";
		code = code || " )";
		eval(parse("dt &amp;lt;&amp;lt; new column(" || name || ", formula(" || code || "));"));
		// Uncomment the next line to remove the formula for the column.  This 
		// will probably make the data table run faster
		//column(dt,ncols(dt)) &amp;lt;&amp;lt; delete property("formula");
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 18 May 2023 22:23:48 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2023-05-18T22:23:48Z</dc:date>
    <item>
      <title>How can I get the sum of all different combinations of a group of columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/632913#M83127</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am using JMP PRO v16&lt;/P&gt;&lt;P&gt;I have a group of 10 columns with numerical values, and I want to try to get a sum of the scores in all possible combinations between these 10 columns (e.g., column A+ column B, column A+ column B + Column C, Column B + Column C and so on).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your help&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 18:49:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/632913#M83127</guid>
      <dc:creator>DivisiveFerret8</dc:creator>
      <dc:date>2023-05-18T18:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the sum of all different combinations of a group of columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/632956#M83131</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/47977"&gt;@DivisiveFerret8&lt;/a&gt;.,&lt;/P&gt;
&lt;P&gt;I don't know of a fast way to do this interactively in JMP, but with some jsl we can make those columns quickly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here (1);

dt = Current Data Table();

// Get the number of columns
ncols = N Col( dt );

// Nested loop to go through all pairwise combinations of columns
For( i = 1, i &amp;lt; ncols, i++,
	For( j = i + 1, j &amp;lt;= ncols, j++,
		colName1 = Column( dt, i ) &amp;lt;&amp;lt; get name;
		colName2 = Column( dt, j ) &amp;lt;&amp;lt; get name;
		
		// create new column
		newColName = colName1 || " + " || colName2;
		dt &amp;lt;&amp;lt; New Column( newColName, Numeric, "Continuous", Format( "Best", 12 ) );

		// compute the sum
		Column( dt, newColName ) &amp;lt;&amp;lt; set each value(
			Column( dt, colName1 )[Row()] + Column( dt, colName2 )[Row()]
		);
	)
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;//EDIT//&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code is for all combinations of columns in the table, but I see now you were asking about a group of columns:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here (1);&lt;BR /&gt;dt = Current Data Table();

// List of specific columns
// columns = {"Column A", "Column B", "Column C", "Column D", "Column E", "Column F", "Column G", "Column H", "Column I", "Column J"};

// Using selected columns
// columns = dt &amp;lt;&amp;lt; Get Selected Columns;

// Referencing by Group Name
columns = dt &amp;lt;&amp;lt; get column group( "XY" );

// Number of specific columns
ncols = N Items( columns );

// Nested loop to go through all pairwise combinations of specified columns
For( i = 1, i &amp;lt; ncols, i++,
	For( j = i + 1, j &amp;lt;= ncols, j++,
		colName1 = columns[i]&amp;lt;&amp;lt;Get Name;
		colName2 = columns[j]&amp;lt;&amp;lt;Get Name;
		
		// create new column
		newColName = colName1 || " + " || colName2;
		dt &amp;lt;&amp;lt; New Column( newColName, Numeric, "Continuous", Format( "Best", 12 ) );

		// compute the sum
		Column( dt, newColName ) &amp;lt;&amp;lt; set each value(
			Column( dt, colName1 )[Row()] + Column( dt, colName2 )[Row()]
		);
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I left some other options in there, like a list of specific columns, or using selected columns.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&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;</description>
      <pubDate>Thu, 18 May 2023 20:39:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/632956#M83131</guid>
      <dc:creator>jules</dc:creator>
      <dc:date>2023-05-18T20:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the sum of all different combinations of a group of columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/632966#M83133</link>
      <description>&lt;P&gt;Thank you so much! I think this script only produces pairwise combinations, is there a way to have all possible combinations? (i.e, all the possible combinations of 2, 3, 4, 5, 6, 7, 8 and 9 columns),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again for your help,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 21:03:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/632966#M83133</guid>
      <dc:creator>DivisiveFerret8</dc:creator>
      <dc:date>2023-05-18T21:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the sum of all different combinations of a group of columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/632969#M83134</link>
      <description>&lt;P&gt;I am really not clear on exactly what the end result needs to be.&amp;nbsp; However, below is a script that sums up all combinations of columns for a data table that has 7(not 10, but will work with 10) numeric columns.&amp;nbsp; It creates a new table with the sum for each of the combination of columns being created.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1684444405614.png" style="width: 657px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/52880iBEDA1EA26558AA4D/image-dimensions/657x703?v=v2" width="657" height="703" role="button" title="txnelson_0-1684444405614.png" alt="txnelson_0-1684444405614.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = 
// Open Data Table: Blood Pressure.jmp
// → Data Table( "Blood Pressure" )
Open( "$SAMPLE_DATA/Blood Pressure.jmp" );

startCol = 3;
endCol = N Col( dt ) - startCol - 1;

colNames = dt &amp;lt;&amp;lt; get column names( string );
Remove From( colNames, 1, startCol - 1 );

dtOutput = New Table( "output", New Column( "Columns Used", character ), New Column( "Sum" ) );

// Build Combinations
For( nInCombo = 2, nInCombo &amp;lt;= endCol, nInCombo++,
	combos = NChooseK Matrix( endCol, nInCombo );
	Show( endcol, combos );
	For( row = 1, row &amp;lt;= N Rows( combos ), row++,
		Current Data Table( dt );
		name = "";
		cols = N Cols( combos );
		code = "x=Sum( col sum( :\!"" || colNames[combos[row, 1, 1]] || "\!"n)";
		name = colNames[combos[row, 1, 1]];
		For( col = 2, col &amp;lt;= cols, col++,
			code = code || ", col sum( :\!"" || colNames[combos[row, col, 1]] || "\!"n)";
			name = name || " + " || colNames[combos[row, col, 1]];
		);
		code = code || " )";
		Eval( Parse( code ) );
		dtOutput &amp;lt;&amp;lt; add rows( 1 );
		dtOutput:Columns Used[N Rows( dtOutput )] = name;
		dtOutput:Sum[N Rows( dtOutput )] = x;
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the summations done row by row, my code can easily be changed to create in the existing data table,&amp;nbsp; a new column&amp;nbsp; for each of the combinations&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 21:15:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/632969#M83134</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-05-18T21:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the sum of all different combinations of a group of columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/632977#M83136</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your help,&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is exactly what I was looking for, I need to get a column with the sum of each of the combinations if possible (all possible combinations of 2, 3, 4, 5, 6, 7, 8 AND 9 columns)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am just starting in JSL and I really appreciate all your help,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 21:31:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/632977#M83136</guid>
      <dc:creator>DivisiveFerret8</dc:creator>
      <dc:date>2023-05-18T21:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the sum of all different combinations of a group of columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/633000#M83139</link>
      <description>&lt;P&gt;Here is the modification to the code that I previously submitted.&amp;nbsp; This code add a new column for each combination of the first 10 columns.&amp;nbsp; It adds 1013 new columns.&amp;nbsp; Please check the correctness of the additions to the data table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = data table("sum combined");

startCol = 2;
endCol = N Col( dt ) ;

colNames = dt &amp;lt;&amp;lt; get column names( string );

// Build Combinations
For( nInCombo = 2, nInCombo &amp;lt;= endCol, nInCombo++,
	combos = NChooseK Matrix( endCol, nInCombo );
	For( row = 1, row &amp;lt;= N Rows( combos ), row++,
		// create the column name and the formula for the new column
		name = "";
		cols = N Cols( combos );
		code = "Sum(  :\!"" || colNames[combos[row, 1, 1]] || "\!"n";
		name = "\!"" || colNames[combos[row, 1, 1]];
		For( col = 2, col &amp;lt;= cols, col++,
			code = code || ",  :\!"" || colNames[combos[row, col, 1]] || "\!"n";
			name = name || " + " || colNames[combos[row, col, 1]];
		);
		name = name || "\!"";
		code = code || " )";
		eval(parse("dt &amp;lt;&amp;lt; new column(" || name || ", formula(" || code || "));"));
		// Uncomment the next line to remove the formula for the column.  This 
		// will probably make the data table run faster
		//column(dt,ncols(dt)) &amp;lt;&amp;lt; delete property("formula");
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 May 2023 22:23:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/633000#M83139</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-05-18T22:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get the sum of all different combinations of a group of columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/633011#M83140</link>
      <description>&lt;P&gt;Thank you so much Jim for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 22:46:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-can-I-get-the-sum-of-all-different-combinations-of-a-group/m-p/633011#M83140</guid>
      <dc:creator>DivisiveFerret8</dc:creator>
      <dc:date>2023-05-18T22:46:04Z</dc:date>
    </item>
  </channel>
</rss>

