<?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 to make a subset of a table and append data from loop in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/how-to-make-a-subset-of-a-table-and-append-data-from-loop/m-p/9694#M9486</link>
    <description>&lt;P&gt;This one was a bit tricky.&amp;nbsp; The main fix is to use AS COLUMN in your select statement.&amp;nbsp; I changed the logic to use get rows where and build up a list of rows to subset/delete.&amp;nbsp; The get_unique_values function is courtesy of this forum!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;get_unique_values = Function( {in_list},
	{Default Local},
	tmp = [=&amp;gt; 0];
	Insert Into( tmp, in_list );
	tmp &amp;lt;&amp;lt; get keys;
);
&amp;nbsp;
path = "c:\temp\";
New_table = Open( path || "Sample Data.jmp" );
&amp;nbsp;
all_selected_rows = [];
&amp;nbsp;
For( k = 1, k &amp;lt; N Col( New_table ), k++,
	Print( k );
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;	selected_rows = new_table &amp;lt;&amp;lt; get rows where( As Column( 1 + k ) &amp;gt;= .2 | As Column( 1 + k ) &amp;lt;= .02 );
&amp;nbsp;
// Append the rows we just found to the master list
&amp;nbsp;&amp;nbsp;&amp;nbsp;	If( N Rows( selected_rows ) &amp;gt; 0,
		all_selected_rows = all_selected_rows |/ selected_rows
	);
);
&amp;nbsp;
// Convert matrix to a list and get unique values
all_selected_list = get_unique_values( As List( all_selected_rows ) );
&amp;nbsp;
alp = New_table &amp;lt;&amp;lt; Subset( rows( all_selected_list ), output table name( "Rejected Parts Table" ) );
&amp;nbsp;
alp &amp;lt;&amp;lt; Save( path || "Rejected Parts.jmp" );
&amp;nbsp;
Close( alp );
&amp;nbsp;
New_table &amp;lt;&amp;lt; delete rows( all_selected_list );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 22 Jul 2018 23:49:25 GMT</pubDate>
    <dc:creator>pmroz</dc:creator>
    <dc:date>2018-07-22T23:49:25Z</dc:date>
    <item>
      <title>how to make a subset of a table and append data from loop</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-make-a-subset-of-a-table-and-append-data-from-loop/m-p/9693#M9485</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a set of data, (see attached). &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;i want to check every row on a column (against a certain criteria) and then isolate rows that do not meet that criteria and subset them into a new data table. i want to be able to repeat this for multiple columns (where each has its own criteria) and continue adding to this subset table that i originally created. i'm having some trouble with this and was hoping if someone could help.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is what i was doing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;path = "xxxxxxx/";
data_table = Open( path || "Sample Data.jmp" );
Sub_Table = New Table( "Rejected Parts Table", invisible );
&amp;nbsp;
New_table = data_table;
For( k = 1, k &amp;lt; N Col( New_table ), k++,
	Print( k );
	New_table &amp;lt;&amp;lt; select where( Column( 1 + k )[] &amp;gt;= 0.2 | Column( 1 + k )[] &amp;lt;= 0.02 );
	alp = New_table &amp;lt;&amp;lt; Subset( Selected Rows, output table name( "subset" ) );
	alp &amp;lt;&amp;lt; Concatenate( Sub_Table, output table name( "Rejected Parts Table" ) ) &amp;lt;&amp;lt;
	Save( path || "Rejected Parts.jmp" );
	Close( alp );
	New_table &amp;lt;&amp;lt; delete rows();
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P style="font-size: 12px; font-family: Courier; color: #942193;"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jul 2018 23:48:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-make-a-subset-of-a-table-and-append-data-from-loop/m-p/9693#M9485</guid>
      <dc:creator>bk</dc:creator>
      <dc:date>2018-07-22T23:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to make a subset of a table and append data from loop</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-make-a-subset-of-a-table-and-append-data-from-loop/m-p/9694#M9486</link>
      <description>&lt;P&gt;This one was a bit tricky.&amp;nbsp; The main fix is to use AS COLUMN in your select statement.&amp;nbsp; I changed the logic to use get rows where and build up a list of rows to subset/delete.&amp;nbsp; The get_unique_values function is courtesy of this forum!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;get_unique_values = Function( {in_list},
	{Default Local},
	tmp = [=&amp;gt; 0];
	Insert Into( tmp, in_list );
	tmp &amp;lt;&amp;lt; get keys;
);
&amp;nbsp;
path = "c:\temp\";
New_table = Open( path || "Sample Data.jmp" );
&amp;nbsp;
all_selected_rows = [];
&amp;nbsp;
For( k = 1, k &amp;lt; N Col( New_table ), k++,
	Print( k );
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;	selected_rows = new_table &amp;lt;&amp;lt; get rows where( As Column( 1 + k ) &amp;gt;= .2 | As Column( 1 + k ) &amp;lt;= .02 );
&amp;nbsp;
// Append the rows we just found to the master list
&amp;nbsp;&amp;nbsp;&amp;nbsp;	If( N Rows( selected_rows ) &amp;gt; 0,
		all_selected_rows = all_selected_rows |/ selected_rows
	);
);
&amp;nbsp;
// Convert matrix to a list and get unique values
all_selected_list = get_unique_values( As List( all_selected_rows ) );
&amp;nbsp;
alp = New_table &amp;lt;&amp;lt; Subset( rows( all_selected_list ), output table name( "Rejected Parts Table" ) );
&amp;nbsp;
alp &amp;lt;&amp;lt; Save( path || "Rejected Parts.jmp" );
&amp;nbsp;
Close( alp );
&amp;nbsp;
New_table &amp;lt;&amp;lt; delete rows( all_selected_list );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jul 2018 23:49:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-make-a-subset-of-a-table-and-append-data-from-loop/m-p/9694#M9486</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2018-07-22T23:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to make a subset of a table and append data from loop</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-make-a-subset-of-a-table-and-append-data-from-loop/m-p/9695#M9487</link>
      <description>&lt;P&gt;An alternative approach using the same criteria for all columns:&lt;/P&gt;
&lt;P style="font-size: 14px; font-family: Courier; color: #942193;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Data Table( "Sample Data.jmp" );
r = Loc( V Sum( Transpose( !(0.02 &amp;lt; dt &amp;lt;&amp;lt; get as matrix &amp;lt; 0.2) ) ) );
dt &amp;lt;&amp;lt; Subset( rows( r ), output table name( "Rejected Parts Table" ) );
dt &amp;lt;&amp;lt; delete rows( r );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Slightly more complicated when each column has its own criteria, for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Data Table( "Sample Data.jmp" );
upper = [0.2 0.3 0.2 0.4 0.2];
lower = [0.02 0.03 0.02 0.04 0.02];
r = Loc( V Sum( Transpose( !(Repeat( lower, N Row( dt ) ) &amp;lt; dt &amp;lt;&amp;lt; get as matrix &amp;lt; Repeat( upper, N Row( dt ) )) ) ) );
dt &amp;lt;&amp;lt; Subset( rows( r ), output table name( "Rejected Parts Table" ) );
dt &amp;lt;&amp;lt; delete rows( r );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN style="color: #011993;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jul 2018 23:58:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-make-a-subset-of-a-table-and-append-data-from-loop/m-p/9695#M9487</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2018-07-22T23:58:31Z</dc:date>
    </item>
  </channel>
</rss>

