<?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 look up data and create new column based on nearest match? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-look-up-data-and-create-new-column-based-on-nearest-match/m-p/214997#M42984</link>
    <description>&lt;OL&gt;
&lt;LI&gt;Assuming the Lookup Table(efficiency) is sorted from low to high on column IOUT&lt;/LI&gt;
&lt;LI&gt;Assuming the Lookup Table is not real large. The methodology being used is not very efficient.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;This code should work well&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;/* Open a sample data table */
//dt = Open( "C:\Users\Test\Sample data\Sample1.jmp" );
dt = Data Table( "Sample1" );

/* Add a column for the assignment */
dt &amp;lt;&amp;lt; New Column( "Efficiency", Numeric );

/* Open a lookup table */
//lt = Open( "C:\Users\Test\Sample data\efficiency_0.7.jmp" );
lt = Data Table( "efficiency" );


/* Loop through each row of the original data table */
For( i = 1, i &amp;lt;= N Rows( dt ), i++, 
	// Find the row with the closest IOUT value below the data value
	theLowRow = Max( lt &amp;lt;&amp;lt; get rows where( lt:IOUT &amp;lt;= dt:data[i] ) );
	// Get the IOUT value for theLowRow
	low = lt:IOUT[theLowRow];
	
	// Find the row with the closest IOUT value above the data value
	theHighRow = Min( lt &amp;lt;&amp;lt; get rows where( lt:IOUT &amp;gt;= dt:data[i] ) );
	// Get the IOUT value for theLowRow
	high = lt:IOUT[theHighRow];
	
	// Find the closest of these two values and write the Efficiency value
	If( Abs( low - dt:data[i] ) &amp;lt; Abs( high - dt:data[i] ),
		dt:Efficiency[i] = lt:low[theLowRow],
		dt:Efficiency[i] = lt:low[theHighRow]
	);
	
	/*/* Obtain a matrix contining the row number of the lookup table
	   where the current falls within the range */
	lowRange = lt &amp;lt;&amp;lt; Get Rows Where(
		Column( lt, "IOUT" )[] &amp;lt; Column( dt, "data" )[i] &amp;amp; 
		Column( dt, "data" )[i] &amp;lt;= Column( lt, "IOUT" )[]
	);
	/* Extract the row number from the matrix */
	r = lowRange[1];
	/* Assign the efficiency value to the original data table */
	Column( dt, "Efficiency" )[i] = Column( lt, "low" )[r];*/
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 27 Jun 2019 13:05:37 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2019-06-27T13:05:37Z</dc:date>
    <item>
      <title>How to look up data and create new column based on nearest match?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-look-up-data-and-create-new-column-based-on-nearest-match/m-p/214944#M42973</link>
      <description>&lt;UL&gt;&lt;LI&gt;I have sample data in table sample1 and the look up table efficiency( please find attached both the tables). I want to find the closest match of data column in&amp;nbsp;table sample1 with resplect to IOUT column in&amp;nbsp;look up table efficiency. Based on the nearest match I want to populate efficiency column in table sample1 in accordance with look up table:&lt;/LI&gt;&lt;LI&gt;Below is the code I am trying&lt;BR /&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;/* Open a sample data table */
dt = Open( "C:\Users\Test\Sample data\Sample1.jmp" );

/* Add a column for the assignment */
dt &amp;lt;&amp;lt; New Column( "Efficiency", Numeric );

/* Open a lookup table */
lt = Open( "C:\Users\Test\Sample data\efficiency_0.7.jmp" );
/* Loop through each row of the original data table */
For( i = 1, i &amp;lt;= N Rows( dt ), i++, 
	/* Obtain a matrix contining the row number of the lookup table
	   where the current falls within the range */
	lowRange = lt &amp;lt;&amp;lt; Get Rows Where(
		Column( lt, "IOUT" )[] &amp;lt; Column( dt, "data" )[i] &amp;amp; 
		Column( dt, "data" )[i] &amp;lt;= Column( lt, "IOUT" )[]
	);
	/* Extract the row number from the matrix */
	r = lowRange[1];
	/* Assign the efficiency value to the original data table */
	Column( dt, "Efficiency" )[i] = Column( lt, "low" )[r];
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI&gt;&lt;LI&gt;I want to find nearest match of IOUT with data and populate the efficiency accordingly&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Fri, 09 Jun 2023 23:25:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-look-up-data-and-create-new-column-based-on-nearest-match/m-p/214944#M42973</guid>
      <dc:creator>jojmp</dc:creator>
      <dc:date>2023-06-09T23:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to look up data and create new column based on nearest match?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-look-up-data-and-create-new-column-based-on-nearest-match/m-p/214966#M42976</link>
      <description>&lt;P&gt;This reply is not a solution but a suggestion about a direction you might take. See the JSL matrix functions for distance metrics. Similarly, you might use a JMP platform that is based on distance for agglomeration, such as clustering or discrimination.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 09:32:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-look-up-data-and-create-new-column-based-on-nearest-match/m-p/214966#M42976</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2019-06-27T09:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to look up data and create new column based on nearest match?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-look-up-data-and-create-new-column-based-on-nearest-match/m-p/214997#M42984</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Assuming the Lookup Table(efficiency) is sorted from low to high on column IOUT&lt;/LI&gt;
&lt;LI&gt;Assuming the Lookup Table is not real large. The methodology being used is not very efficient.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;This code should work well&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;/* Open a sample data table */
//dt = Open( "C:\Users\Test\Sample data\Sample1.jmp" );
dt = Data Table( "Sample1" );

/* Add a column for the assignment */
dt &amp;lt;&amp;lt; New Column( "Efficiency", Numeric );

/* Open a lookup table */
//lt = Open( "C:\Users\Test\Sample data\efficiency_0.7.jmp" );
lt = Data Table( "efficiency" );


/* Loop through each row of the original data table */
For( i = 1, i &amp;lt;= N Rows( dt ), i++, 
	// Find the row with the closest IOUT value below the data value
	theLowRow = Max( lt &amp;lt;&amp;lt; get rows where( lt:IOUT &amp;lt;= dt:data[i] ) );
	// Get the IOUT value for theLowRow
	low = lt:IOUT[theLowRow];
	
	// Find the row with the closest IOUT value above the data value
	theHighRow = Min( lt &amp;lt;&amp;lt; get rows where( lt:IOUT &amp;gt;= dt:data[i] ) );
	// Get the IOUT value for theLowRow
	high = lt:IOUT[theHighRow];
	
	// Find the closest of these two values and write the Efficiency value
	If( Abs( low - dt:data[i] ) &amp;lt; Abs( high - dt:data[i] ),
		dt:Efficiency[i] = lt:low[theLowRow],
		dt:Efficiency[i] = lt:low[theHighRow]
	);
	
	/*/* Obtain a matrix contining the row number of the lookup table
	   where the current falls within the range */
	lowRange = lt &amp;lt;&amp;lt; Get Rows Where(
		Column( lt, "IOUT" )[] &amp;lt; Column( dt, "data" )[i] &amp;amp; 
		Column( dt, "data" )[i] &amp;lt;= Column( lt, "IOUT" )[]
	);
	/* Extract the row number from the matrix */
	r = lowRange[1];
	/* Assign the efficiency value to the original data table */
	Column( dt, "Efficiency" )[i] = Column( lt, "low" )[r];*/
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jun 2019 13:05:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-look-up-data-and-create-new-column-based-on-nearest-match/m-p/214997#M42984</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-06-27T13:05:37Z</dc:date>
    </item>
  </channel>
</rss>

