<?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: Append matrices from a loop in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Append-matrices-from-a-loop/m-p/437575#M68638</link>
    <description>&lt;P&gt;This function might be useful.&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="matrix.PNG" style="width: 804px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/37641iDEC269CA5B360E29/image-size/large?v=v2&amp;amp;px=999" role="button" title="matrix.PNG" alt="matrix.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Nov 2021 16:03:24 GMT</pubDate>
    <dc:creator>Mark_Bailey</dc:creator>
    <dc:date>2021-11-17T16:03:24Z</dc:date>
    <item>
      <title>Append matrices from a loop</title>
      <link>https://community.jmp.com/t5/Discussions/Append-matrices-from-a-loop/m-p/437271#M68623</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am trying to generate a matrix with the following scripts and have a few questions:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1. in order to correctly get "row" do I need to first sort the fruit column? Is there a Random formula to pick just one number out of "r"?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2. I need the final "run" matrix with the furitName info (the i variable) and be just one matrix. The current script I had would generate 3 run matrices (depending on the N Items(fruitName))&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3. Once all run matrices are concatenated in one, is there a way to output the matrix to a data table?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;TIA!&lt;/SPAN&gt;&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;Names Default To Here( 1 );
dt = Current Data Table();
Summarize( dt, fruitName = by( :fruit ) );
For( i = 1, i &amp;lt;= N Items( fruitName ), i++,
	r = dt &amp;lt;&amp;lt; get rows where( :fruit == fruitName[i] );
	row = Random Integer( Max( r ) - Min( r ) );
/*show(r);
show(row);*/
	runTime = 5;
	run = [](0, 2);
	For( j = 1, j &amp;lt;= runTime, j++,
		row = Random Integer( Max( r ) - Min( r ) );
		run |/= Matrix( {{j, dt:name( "price hi" )[row] - dt:price lo[row]}} );
	);
	Show( run );
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 18:05:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Append-matrices-from-a-loop/m-p/437271#M68623</guid>
      <dc:creator>midori555</dc:creator>
      <dc:date>2023-06-09T18:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Append matrices from a loop</title>
      <link>https://community.jmp.com/t5/Discussions/Append-matrices-from-a-loop/m-p/437433#M68624</link>
      <description>&lt;P&gt;Here are a couple of ways to do what I think you are looking for&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();
Summarize( dt, fruitName = by( :fruit ) );
runTime = 5;
run = [](0, 2);
fruitList ={};
For( i = 1, i &amp;lt;= N Items( fruitName ), i++,
	r = dt &amp;lt;&amp;lt; get rows where( :fruit == fruitName[i] );
	
	For( j = 1, j &amp;lt;= runTime, j++,
		insert into(fruitList, fruitName[i]);
		row = r[Random Integer( nrows(r))];

		run |/= Matrix( {{j, dt:name( "price hi" )[row] - dt:price lo[row]}} );
	);
);

dtNew = New Table("Random",
	add rows(n rows(run)),
	new column("Fruit", character,set each value(fruitList[Row()])),
	new column("Delta", set each value(run[row(),2]))
);

// or

dtNew2 = dt &amp;lt;&amp;lt; Subset(
	Sample Size( runTime ),
	Selected columns only( 0 ),
	Stratify( :fruit )
);
dtNew2 &amp;lt;&amp;lt; New Column( "Delta", set each value( :price hi - :price lo ) );
dtNew2 &amp;lt;&amp;lt; delete columns( {"price hi", "price lo"} );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Nov 2021 08:45:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Append-matrices-from-a-loop/m-p/437433#M68624</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-11-17T08:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Append matrices from a loop</title>
      <link>https://community.jmp.com/t5/Discussions/Append-matrices-from-a-loop/m-p/437575#M68638</link>
      <description>&lt;P&gt;This function might be useful.&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="matrix.PNG" style="width: 804px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/37641iDEC269CA5B360E29/image-size/large?v=v2&amp;amp;px=999" role="button" title="matrix.PNG" alt="matrix.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 16:03:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Append-matrices-from-a-loop/m-p/437575#M68638</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2021-11-17T16:03:24Z</dc:date>
    </item>
  </channel>
</rss>

