<?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: Atuomate assigning columns to groups in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Atuomate-assigning-columns-to-groups/m-p/809421#M98959</link>
    <description>&lt;P&gt;I use almost the same idea as Jim, but I like separating the group collection and creation into their own loops&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);


dt1 = New Table("Table1",
	Add Rows(3),
	New Column("A", Numeric, "Continuous", Format("Best", 12), Set Values([35, 10, 88])),
	New Column("B", Numeric, "Continuous", Format("Best", 12), Set Values([2, 3, 2])),
	New Column("C", Numeric, "Continuous", Format("Best", 12), Set Values([1, 3, 1])),
	New Column("D", Numeric, "Continuous", Format("Best", 12), Set Values([2, 2, 2]))
);

dt2 = New Table("Table2",
	Add Rows(4),
	New Column("Name", Character, "Nominal", Set Values({"A", "B", "C", "D"})),
	New Column("GroupName", Character, "Nominal", Set Values({"G1", "G1", "G2", "G2"}))
);

aa_groups = Associative Array(Column(dt2, "GroupName"));

For Each({key}, aa_groups &amp;lt;&amp;lt; get keys,
	aa_groups[key] = dt2 &amp;lt;&amp;lt; Get Rows Where(:GroupName == key);
);

For Each({{name, cols}}, aa_groups,
	dt1 &amp;lt;&amp;lt; Group Columns(name, cols);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 01 Nov 2024 04:57:04 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2024-11-01T04:57:04Z</dc:date>
    <item>
      <title>Atuomate assigning columns to groups</title>
      <link>https://community.jmp.com/t5/Discussions/Atuomate-assigning-columns-to-groups/m-p/809418#M98957</link>
      <description>&lt;P&gt;I've been struggling to figure this out. &amp;nbsp;I have a table (Table1) that has columns that I want grouped. &amp;nbsp;Table2 has the column names and group labels I want to use. &amp;nbsp;I want to script and automate creating the grouped table, as shown in the screenshot below. &amp;nbsp;Any suggestions on how to do this would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MathStatChem_0-1730417109484.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/69740i173E938755B01D13/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MathStatChem_0-1730417109484.png" alt="MathStatChem_0-1730417109484.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here are scripts to create Table1 and Table2 shown above&lt;/P&gt;&lt;PRE&gt;dt1 = New Table( "Table1",
	Add Rows( 3 ),
	New Column( "A", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [35, 10, 88] ) ),
	New Column( "B", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 3, 2] ) ),
	New Column( "C", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 3, 1] ) ),
	New Column( "D", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 2, 2] ) )
);

dt2 = New Table( "Table2",
	Add Rows( 4 ),
	New Column( "Name", Character, "Nominal", Set Values( {"A", "B", "C", "D"} ) ),
	New Column( "GroupName", Character, "Nominal", Set Values( {"G1", "G1", "G2", "G2"} ) )
);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2024 23:26:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Atuomate-assigning-columns-to-groups/m-p/809418#M98957</guid>
      <dc:creator>MathStatChem</dc:creator>
      <dc:date>2024-10-31T23:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Atuomate assigning columns to groups</title>
      <link>https://community.jmp.com/t5/Discussions/Atuomate-assigning-columns-to-groups/m-p/809420#M98958</link>
      <description>&lt;P&gt;Here is one way to handle the issue:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 ); 

dt1 = New Table( "Table1",
	Add Rows( 3 ),
	New Column( "A", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [35, 10, 88] ) ),
	New Column( "B", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 3, 2] ) ),
	New Column( "C", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 3, 1] ) ),
	New Column( "D", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 2, 2] ) )
);

dt2 = New Table( "Table2",
	Add Rows( 4 ),
	New Column( "Name", Character, "Nominal", Set Values( {"A", "B", "C", "D"} ) ),
	New Column( "GroupName", Character, "Nominal", Set Values( {"G1", "G1", "G2", "G2"} ) )
);

GroupNames = Associative Array( dt2:GroupName ) &amp;lt;&amp;lt; get keys;
For Each( {theGroup}, GroupNames, 
	// Create a list for a group
	theRows = dt2 &amp;lt;&amp;lt; get rows where( :GroupName == theGroup );
	grpList = {};
	For Each( {rowValue}, theRows, Insert Into( grpList, dt2:Name[rowValue] ) );
	dt1 &amp;lt;&amp;lt; Group Columns( theGroup, grpList );
)
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Nov 2024 02:17:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Atuomate-assigning-columns-to-groups/m-p/809420#M98958</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-11-01T02:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Atuomate assigning columns to groups</title>
      <link>https://community.jmp.com/t5/Discussions/Atuomate-assigning-columns-to-groups/m-p/809421#M98959</link>
      <description>&lt;P&gt;I use almost the same idea as Jim, but I like separating the group collection and creation into their own loops&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);


dt1 = New Table("Table1",
	Add Rows(3),
	New Column("A", Numeric, "Continuous", Format("Best", 12), Set Values([35, 10, 88])),
	New Column("B", Numeric, "Continuous", Format("Best", 12), Set Values([2, 3, 2])),
	New Column("C", Numeric, "Continuous", Format("Best", 12), Set Values([1, 3, 1])),
	New Column("D", Numeric, "Continuous", Format("Best", 12), Set Values([2, 2, 2]))
);

dt2 = New Table("Table2",
	Add Rows(4),
	New Column("Name", Character, "Nominal", Set Values({"A", "B", "C", "D"})),
	New Column("GroupName", Character, "Nominal", Set Values({"G1", "G1", "G2", "G2"}))
);

aa_groups = Associative Array(Column(dt2, "GroupName"));

For Each({key}, aa_groups &amp;lt;&amp;lt; get keys,
	aa_groups[key] = dt2 &amp;lt;&amp;lt; Get Rows Where(:GroupName == key);
);

For Each({{name, cols}}, aa_groups,
	dt1 &amp;lt;&amp;lt; Group Columns(name, cols);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Nov 2024 04:57:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Atuomate-assigning-columns-to-groups/m-p/809421#M98959</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-11-01T04:57:04Z</dc:date>
    </item>
  </channel>
</rss>

