<?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 How to find the average of samples at random intervals? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-find-the-average-of-samples-at-random-intervals/m-p/335794#M58323</link>
    <description>&lt;P&gt;I have a csv file that stores temp values. I have to find the group average for certain set of samples according to below steps:&lt;/P&gt;&lt;P&gt;1. Make all temp values les than 25 equal to zero i.e.column post_process&lt;/P&gt;&lt;P&gt;2. group_avg column is derived by ignoring rows with greater than or equal to 4 consecutive zeroes. Followed by calculating the average of the group of samples as shown below&lt;/P&gt;&lt;P&gt;3. final_average column is the results generated from group_avg column&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can we script this process using jsl?&lt;/P&gt;&lt;P&gt;Attaching the csv file&lt;/P&gt;&lt;P&gt;Final result is final&lt;SPAN style="font-family: inherit;"&gt;_average as in the table below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jojmp_0-1605845994525.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/28497i81222E48BFCD84BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jojmp_0-1605845994525.png" alt="jojmp_0-1605845994525.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 10 Jun 2023 23:22:37 GMT</pubDate>
    <dc:creator>jojmp</dc:creator>
    <dc:date>2023-06-10T23:22:37Z</dc:date>
    <item>
      <title>How to find the average of samples at random intervals?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-find-the-average-of-samples-at-random-intervals/m-p/335794#M58323</link>
      <description>&lt;P&gt;I have a csv file that stores temp values. I have to find the group average for certain set of samples according to below steps:&lt;/P&gt;&lt;P&gt;1. Make all temp values les than 25 equal to zero i.e.column post_process&lt;/P&gt;&lt;P&gt;2. group_avg column is derived by ignoring rows with greater than or equal to 4 consecutive zeroes. Followed by calculating the average of the group of samples as shown below&lt;/P&gt;&lt;P&gt;3. final_average column is the results generated from group_avg column&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can we script this process using jsl?&lt;/P&gt;&lt;P&gt;Attaching the csv file&lt;/P&gt;&lt;P&gt;Final result is final&lt;SPAN style="font-family: inherit;"&gt;_average as in the table below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jojmp_0-1605845994525.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/28497i81222E48BFCD84BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jojmp_0-1605845994525.png" alt="jojmp_0-1605845994525.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:22:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-find-the-average-of-samples-at-random-intervals/m-p/335794#M58323</guid>
      <dc:creator>jojmp</dc:creator>
      <dc:date>2023-06-10T23:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the average of samples at random intervals?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-find-the-average-of-samples-at-random-intervals/m-p/335813#M58324</link>
      <description>&lt;P&gt;Here is a script that creates your data table with just the TEMP column, and then the remaining columns are created and formula are used to populate them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = New Table( "temp_temp",
	Add Rows( 54 ),
	New Column( "TEMP",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[23.23019577, 23.44946668, 23.56111955, 23.47601143, 23.36428639,
			23.24016499, 32.42091411, 23, 32.26821731, 32.14990084, 32.42091411,
			32.26821731, 32.14990084, 23.23019577, 23.44946668, 23.56111955,
			23.47601143, 23.36428639, 23.24016499, 32.15353181, 32.16785998, 21,
			32.502366, 32.16261133, 32.15757688, 32.16790474, 23.23019577,
			23.44946668, 23.56111955, 23.47601143, 23.36428639, 23.24016499,
			32.42091411, 10, 32.26821731, 32.14990084, 32.41334166, 32.17456755,
			32.52383338, 32.17310331, 19.28571429, 19.28571429, 19.28571429,
			19.28571429, 34.62948075, 34.28766971, 34.29470736, 34.61532486,
			34.386807, 34.36554216, 34.58410721, 34.28726312, 23.57142857,
			23.57142857]
		)
	)
);

dt &amp;lt;&amp;lt; New Column( "post process", formula( If( :TEMP &amp;lt;= 25, 0, :TEMP ) ) );
dt:post process &amp;lt;&amp;lt; delete formula;

dt &amp;lt;&amp;lt; New Column( "group_avg",
	formula(
		value = .;
		If( Row() == 1,
			flag = 0;
			zeroCounter = 0;
		);
		If( flag == 0 &amp;amp; :post process &amp;gt; 0,
			flag = 1;
			captureMatrix = [];
			Show( "start", Row(), flag );
		);
		If( :post process == 0 &amp;amp; flag == 1,
			zeroCounter
			++);
		If( flag == 1,
			captureMatrix = captureMatrix || Matrix( :post process );
			Show( "cap", Row(), captureMatrix );
			If( zeroCounter == 4 | Row() == N Rows( dt ),
				For( i = N Cols( captureMatrix ), i &amp;gt;= 1, i--,
					If( captureMatrix[i] != 0,
						Break(),
						captureMatrix[i] = .
					)
				);
				value = Mean( captureMatrix );
				Show( value );
				Show( Row(), captureMatrix, zeroCounter, Index( 1, N Cols( captureMatrix ) - (zeroCounter - 1) ) );
				flag = 0;
				zeroCounter = 0;
				Show( flag );
				captureMatrix = [];
			);
		);
		value;
	)
);

dt &amp;lt;&amp;lt; new column("final Avg",
	formula(
		if(row()==1,
			theRows = current data table() &amp;lt;&amp;lt; get rows where(isMissing(:group_avg)==0);
		);
		If(row()&amp;lt;= nrows(theRows),
			value=:group_avg[theRows[Row()]],
			value=.
		)
	)
);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Nov 2020 06:38:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-find-the-average-of-samples-at-random-intervals/m-p/335813#M58324</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-11-20T06:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the average of samples at random intervals?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-find-the-average-of-samples-at-random-intervals/m-p/335816#M58326</link>
      <description>&lt;P&gt;This scripts works fine for small files. But in case of large files where we have 16000 zeroes instead of 4 JMP stops responding. Is there any way to prevent this and run the script without hang?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 09:22:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-find-the-average-of-samples-at-random-intervals/m-p/335816#M58326</guid>
      <dc:creator>jojmp</dc:creator>
      <dc:date>2020-11-20T09:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the average of samples at random intervals?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-find-the-average-of-samples-at-random-intervals/m-p/335842#M58327</link>
      <description>&lt;P&gt;I suspect the issue is that by mistake, I left several "Show()" statements in the code, which forced a lot of writing to the JMP log.&lt;/P&gt;
&lt;P&gt;Below is the "post process" column specification, which is the part that I assume is having the issue that is making JMP hang.&amp;nbsp; Try running it and see if it will run without hanging&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt &amp;lt;&amp;lt; New Column( "group_avg",
	formula(
		value = .;
		If( Row() == 1,
			flag = 0;
			zeroCounter = 0;
		);
		If( flag == 0 &amp;amp; :post process &amp;gt; 0,
			flag = 1;
			captureMatrix = [];
		);
		If( :post process == 0 &amp;amp; flag == 1,
			zeroCounter
			++);
		If( flag == 1,
			captureMatrix = captureMatrix || Matrix( :post process );
			If( zeroCounter == 4 | Row() == N Rows( dt ),
				/*For( i = N Cols( captureMatrix ), i &amp;gt;= 1, i--,
					If( captureMatrix[i] != 0,
						Break(),
						captureMatrix[i] = .
					)
				);*/
				if( Row() == N Rows( dt ), zerocounter++ );
				value = Mean( captureMatrix[ 1:: ncols(captureMatrix) - (zeroCounter - 1)] );
				flag = 0;
				zeroCounter = 0;
				captureMatrix = [];
			);
		);
		value;
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Nov 2020 11:25:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-find-the-average-of-samples-at-random-intervals/m-p/335842#M58327</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-11-20T11:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the average of samples at random intervals?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-find-the-average-of-samples-at-random-intervals/m-p/335922#M58332</link>
      <description>&lt;P&gt;The first script gives the correct answer but the output of both the scripts are not same, why have you commented some part of the code&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 17:01:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-find-the-average-of-samples-at-random-intervals/m-p/335922#M58332</guid>
      <dc:creator>jojmp</dc:creator>
      <dc:date>2020-11-20T17:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the average of samples at random intervals?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-find-the-average-of-samples-at-random-intervals/m-p/335925#M58334</link>
      <description>&lt;P&gt;The second version of the code is more efficient. Given the amount of data you are running I thought it would help.&amp;nbsp; It should provide the same results.&amp;nbsp; If it does not, you can try just removing all of the Show() statements from the first version of the code, and if that works.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 17:07:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-find-the-average-of-samples-at-random-intervals/m-p/335925#M58334</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-11-20T17:07:28Z</dc:date>
    </item>
  </channel>
</rss>

