<?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 efficiently find the first position in a specified range of data that meets the requirements? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-efficiently-find-the-first-position-in-a-specified-range/m-p/420568#M66939</link>
    <description>&lt;P&gt;I tried this stupid method and got results.Ask the experts Can this formula be simplified?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;PRE&gt;If( Row() &amp;gt; 30,&lt;BR /&gt;r1 = Contains( height[Index( 1, 30 )], height + 2 );&lt;BR /&gt;r2 = Contains( height[Index( 1, 30 )], height + 1 );&lt;BR /&gt;r3 = Contains( height[Index( 1, 30 )], height );&lt;BR /&gt;r4 = Contains( height[Index( 1, 30 )], height - 1 );&lt;BR /&gt;r5 = Contains( height[Index( 1, 30 )], height - 2 );&lt;BR /&gt;Min( If( r1 == 0, 99, r1 ), If( r2 == 0, 99, r2 ), If( r3 == 0, 99, r3 ), If( r4 == 0, 99, r4 ), If( r5 == 0, 99, r5 ) );&lt;BR /&gt;)&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-09-23_1733.png" style="width: 909px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/36021i8B788F1D71B0F8C7/image-size/large?v=v2&amp;amp;px=999" role="button" title="2021-09-23_1733.png" alt="2021-09-23_1733.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Sep 2021 10:30:23 GMT</pubDate>
    <dc:creator>lwx228</dc:creator>
    <dc:date>2021-09-23T10:30:23Z</dc:date>
    <item>
      <title>How to efficiently find the first position in a specified range of data that meets the requirements?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-efficiently-find-the-first-position-in-a-specified-range/m-p/420041#M66888</link>
      <description>&lt;P&gt;For example, Big Class.jmp&lt;BR /&gt;The calculation steps are:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;if(row()&amp;gt;30,contains(:height[Index(1,30)],abs(:height[Index(1,30)]-:height)&amp;lt;3))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;If the number of lines is greater than 30,&lt;BR /&gt;compare the data with the absolute value difference between the height of lines 1 -- 30 and the height of this line is less than or equal to 2, and calculate the number of lines 1 -- 30 that meet the above conditions first.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-09-22_1904.png" style="width: 485px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/35989i5B6D5844B7E7E1C7/image-size/large?v=v2&amp;amp;px=999" role="button" title="2021-09-22_1904.png" alt="2021-09-22_1904.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks Experts!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 19:57:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-efficiently-find-the-first-position-in-a-specified-range/m-p/420041#M66888</guid>
      <dc:creator>lwx228</dc:creator>
      <dc:date>2023-06-09T19:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to efficiently find the first position in a specified range of data that meets the requirements?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-efficiently-find-the-first-position-in-a-specified-range/m-p/420568#M66939</link>
      <description>&lt;P&gt;I tried this stupid method and got results.Ask the experts Can this formula be simplified?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;PRE&gt;If( Row() &amp;gt; 30,&lt;BR /&gt;r1 = Contains( height[Index( 1, 30 )], height + 2 );&lt;BR /&gt;r2 = Contains( height[Index( 1, 30 )], height + 1 );&lt;BR /&gt;r3 = Contains( height[Index( 1, 30 )], height );&lt;BR /&gt;r4 = Contains( height[Index( 1, 30 )], height - 1 );&lt;BR /&gt;r5 = Contains( height[Index( 1, 30 )], height - 2 );&lt;BR /&gt;Min( If( r1 == 0, 99, r1 ), If( r2 == 0, 99, r2 ), If( r3 == 0, 99, r3 ), If( r4 == 0, 99, r4 ), If( r5 == 0, 99, r5 ) );&lt;BR /&gt;)&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-09-23_1733.png" style="width: 909px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/36021i8B788F1D71B0F8C7/image-size/large?v=v2&amp;amp;px=999" role="button" title="2021-09-23_1733.png" alt="2021-09-23_1733.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 10:30:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-efficiently-find-the-first-position-in-a-specified-range/m-p/420568#M66939</guid>
      <dc:creator>lwx228</dc:creator>
      <dc:date>2021-09-23T10:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to efficiently find the first position in a specified range of data that meets the requirements?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-efficiently-find-the-first-position-in-a-specified-range/m-p/420907#M66964</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/12538"&gt;@lwx228&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure this is any better than your formula, but here is another way to do the same thing (I think).&amp;nbsp; Note that this will be slow for larger tables; if you are dealing with many rows I you could create a lookup table with the desired row number corresponding with all possible values of height and then join it to the table.&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="ih_0-1632485408619.png" style="width: 955px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/36060i027F683F4F804ABF/image-dimensions/955x246?v=v2" width="955" height="246" role="button" title="ih_0-1632485408619.png" alt="ih_0-1632485408619.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() &amp;gt; 30,
	firstrowmatch = 0;
	For( r = 1, r &amp;lt;= 30 &amp;amp; firstrowmatch == 0, r++,
		mtch = Contains( Index( :height - 2, :height + 2, 1 ), :height[r] );
		If( mtch &amp;gt; 0,
			firstrowmatch = r
		);
	);
	firstrowmatch;
)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Sep 2021 12:12:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-efficiently-find-the-first-position-in-a-specified-range/m-p/420907#M66964</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2021-09-24T12:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to efficiently find the first position in a specified range of data that meets the requirements?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-efficiently-find-the-first-position-in-a-specified-range/m-p/420920#M66966</link>
      <description>&lt;P&gt;If I have understood the question correctly this might work (using Loc and matrix subscripting):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(Row() &amp;gt; 30,
	m = Loc(Abs((:height &amp;lt;&amp;lt; get as matrix)[1::30] - :height) &amp;lt; 3, 1);
	If(N Items(m) &amp;gt; 0,
		m[1],
		.
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Full example with Big Class:&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

dt &amp;lt;&amp;lt; New Column("pos", Numeric, Continuous, Formula(
	If(Row() &amp;gt; 30,
		m = Loc(Abs((:height &amp;lt;&amp;lt; get as matrix)[1::30] - :height) &amp;lt; 3, 1);
		If(N Items(m) &amp;gt; 0,
			m[1],
			.
		)
	);
));&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI-SPOILER&gt;</description>
      <pubDate>Fri, 24 Sep 2021 12:45:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-efficiently-find-the-first-position-in-a-specified-range/m-p/420920#M66966</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-09-24T12:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to efficiently find the first position in a specified range of data that meets the requirements?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-efficiently-find-the-first-position-in-a-specified-range/m-p/420933#M66967</link>
      <description>Thanks to the experts for their help. Through the study of these methods, I know more efficient methods.</description>
      <pubDate>Fri, 24 Sep 2021 13:43:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-efficiently-find-the-first-position-in-a-specified-range/m-p/420933#M66967</guid>
      <dc:creator>lwx228</dc:creator>
      <dc:date>2021-09-24T13:43:41Z</dc:date>
    </item>
  </channel>
</rss>

