<?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 do I add data from one table to another table based on the distance in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782451#M96592</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;I still see it is not picking up the closest points: &lt;BR /&gt;Names Default To Here( 1 );
Close All(data tables);
Clear Log();
Clear Symbols();
dt1= Open(
		"C:\Users\Table 1.jmp");
wait(0.0);
dt1:X1 &amp;lt;&amp;lt; suppress eval( true );
dt1:Y1 &amp;lt;&amp;lt; suppress eval( true );
dt2= Open(
		"C:\Users\Table 2.jmp");

wait(0.0);
dt2:X2 &amp;lt;&amp;lt; suppress eval( true );
dt2:Y2 &amp;lt;&amp;lt; suppress eval( true );

M1 = dt1 &amp;lt;&amp;lt; GetAsMatrix();
MD1=vptree(M1);


M2 = dt2 &amp;lt;&amp;lt; GetAsMatrix();
MD2=kdtable(M2);

//returns the nearest point of Table 1 to a point in table 2
//to reverse the look up, make MD1-&amp;gt; MD2 and M2-&amp;gt;M1
{rows, dist} = MD1 &amp;lt;&amp;lt; K nearest rows( 1, M2);

dt1&amp;lt;&amp;lt;new column("same as rows",
							Numeric,
							Ordinal,
								Set Values( rows )
									
			);
			
dt2&amp;lt;&amp;lt;new column("row number",
							Numeric,
							Ordinal,
								Formula(Row())
									
			);
dt1 &amp;lt;&amp;lt; update(
     with(dt2),
     match(:same as rows=:row number),
     ignore missing,
     add columns from update(none)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 18 Aug 2024 21:05:03 GMT</pubDate>
    <dc:creator>spinup</dc:creator>
    <dc:date>2024-08-18T21:05:03Z</dc:date>
    <item>
      <title>How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782399#M96582</link>
      <description>&lt;P&gt;I have two data tables for two set of measurement on the wafer. There are four columns in each table, X, Y representing the location of measurements, and two columns of measurement data for each table. the measurements&amp;nbsp; are not collected from the exact same positions (X,Y) of the wafer.&amp;nbsp; I would like to update ( add extra columns of the other table) either of the tables based on the proximity of measurement locations. To be more clear, I would like to have a combined table ( total 8 columns ) based on matching of&amp;nbsp; X1,Y1 to the closest point on X2, and Y2. Please see the picture I uploaded. I know Distance function probably can be utilized to make a matrix of all distances from a given X,Y but not sure how to write the jsl code to compute the updated table for me.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2024 05:37:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782399#M96582</guid>
      <dc:creator>spinup</dc:creator>
      <dc:date>2024-08-18T05:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782409#M96583</link>
      <description>&lt;P&gt;Check out following functions in addition to Distance&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://help.jmp.com/help?keyword=JSL%20VPTree&amp;amp;lang=en&amp;amp;os=win&amp;amp;source=application&amp;amp;version=18.0.1" target="_self"&gt;VPTree()&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://www.jmp.com/support/help/en/18.0/#page/jmp/matrix-functions.shtml?os=win&amp;amp;source=application#ww4966580" target="_self"&gt;KDTable()&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;And maybe &lt;A href="https://www.jmp.com/support/help/en/18.0/#page/jmp/matrix-functions.shtml?os=win&amp;amp;source=application#ww3287251" target="_self"&gt;Loc Sorted()&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Then add row based index to your "main" table, utilize one of these to find the closest index (basically row), add it to your second table and then finally use update/join to combine the tables.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2024 05:45:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782409#M96583</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-08-18T05:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782445#M96589</link>
      <description>&lt;P&gt;Based upon&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;links I believe this does what you want&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1=New Table( "Table 1",
	Add Rows( 20 ),
	New Column( "x",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( Random Normal() )
	),
	New Column( "y",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( Random Normal() )
	),
	Set Row States( [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] )
);

dt2=New Table( "Table 2",
	Add Rows( 20 ),
	New Column( "x",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( Random Normal() ),
		Set Display Width( 120 )
	),
	New Column( "y",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( Random Normal() ),
		Set Selected,
		Set Display Width( 118 )
	),
	Set Row States( [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] )
);

M1 = dt1 &amp;lt;&amp;lt; GetAsMatrix();
MD1=vptree(M1);

M2 = dt2 &amp;lt;&amp;lt; GetAsMatrix();
MD2=kdtable(M2);

//returns the nearest point of Table 1 to a point in table 2
//to reverse the look up, make MD1-&amp;gt; MD2 and M2-&amp;gt;M1
{rows, dist} = MD1 &amp;lt;&amp;lt; K nearest rows( 1, M2);

dt1&amp;lt;&amp;lt;new column("same as rows",
							Numeric,
							Ordinal,
								Set Values( rows )
									
			);
			
dt2&amp;lt;&amp;lt;new column("row number",
							Numeric,
							Ordinal,
								Formula(Row())
									
			);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2024 19:14:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782445#M96589</guid>
      <dc:creator>shampton82</dc:creator>
      <dc:date>2024-08-18T19:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782447#M96590</link>
      <description>&lt;P&gt;Hi Steve, and Jarmo,&lt;/P&gt;&lt;P&gt;Thanks for the suggestions. The script was also useful. However, when I run I don't think it finds the closest distance. For instance, in the first row of Table 1 matches to row 8 ( distance of ~1.37) of Table 2 but there are many much closer points such as row number 1 ( distance of 0.69)&amp;nbsp; ( let distance to be sqrt[(x-x0)^2+(y-y0)^2])&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="spinup_0-1724010306455.png" style="width: 774px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/67224i6BCFB88FAD9CAE08/image-dimensions/774x293?v=v2" width="774" height="293" role="button" title="spinup_0-1724010306455.png" alt="spinup_0-1724010306455.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2024 19:53:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782447#M96590</guid>
      <dc:creator>spinup</dc:creator>
      <dc:date>2024-08-18T19:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782450#M96591</link>
      <description>&lt;P&gt;I think I mixed up the data tables at the end of the script, try this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1=New Table( "Table 1",
	Add Rows( 20 ),
	New Column( "x",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( Random Normal() )
	),
	New Column( "y",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( Random Normal() )
	),
	Set Row States( [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] )
);
wait(0.0);
dt1:x &amp;lt;&amp;lt; suppress eval( true );
dt1:y &amp;lt;&amp;lt; suppress eval( true );

dt2=New Table( "Table 2",
	Add Rows( 20 ),
	New Column( "x",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( Random Normal() ),
		Set Display Width( 120 )
	),
	New Column( "y",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( Random Normal() ),
		Set Selected,
		Set Display Width( 118 )
	),
	Set Row States( [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] )
);
wait(0.0);
dt2:x &amp;lt;&amp;lt; suppress eval( true );
dt2:y &amp;lt;&amp;lt; suppress eval( true );

M1 = dt1 &amp;lt;&amp;lt; GetAsMatrix();
MD1=vptree(M1);

M2 = dt2 &amp;lt;&amp;lt; GetAsMatrix();
MD2=kdtable(M2);

//returns the nearest point of Table 1 to a point in table 2
//to reverse the look up, make MD1-&amp;gt; MD2 and M2-&amp;gt;M1
{rows, dist} = MD1 &amp;lt;&amp;lt; K nearest rows( 1, M2);

dt2&amp;lt;&amp;lt;new column("same as rows",
							Numeric,
							Ordinal,
								Set Values( rows )
									
			);
			
dt1&amp;lt;&amp;lt;new column("row number",
							Numeric,
							Ordinal,
								Formula(Row())
									
			);
	&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I virtual linked them and did some visual checks so I believe we are good now&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/67225i8663690D9A1ED800/image-size/medium?v=v2&amp;amp;px=400" role="button" title="shampton82_0-1724013813741.png" alt="shampton82_0-1724013813741.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2024 20:43:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782450#M96591</guid>
      <dc:creator>shampton82</dc:creator>
      <dc:date>2024-08-18T20:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782451#M96592</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;I still see it is not picking up the closest points: &lt;BR /&gt;Names Default To Here( 1 );
Close All(data tables);
Clear Log();
Clear Symbols();
dt1= Open(
		"C:\Users\Table 1.jmp");
wait(0.0);
dt1:X1 &amp;lt;&amp;lt; suppress eval( true );
dt1:Y1 &amp;lt;&amp;lt; suppress eval( true );
dt2= Open(
		"C:\Users\Table 2.jmp");

wait(0.0);
dt2:X2 &amp;lt;&amp;lt; suppress eval( true );
dt2:Y2 &amp;lt;&amp;lt; suppress eval( true );

M1 = dt1 &amp;lt;&amp;lt; GetAsMatrix();
MD1=vptree(M1);


M2 = dt2 &amp;lt;&amp;lt; GetAsMatrix();
MD2=kdtable(M2);

//returns the nearest point of Table 1 to a point in table 2
//to reverse the look up, make MD1-&amp;gt; MD2 and M2-&amp;gt;M1
{rows, dist} = MD1 &amp;lt;&amp;lt; K nearest rows( 1, M2);

dt1&amp;lt;&amp;lt;new column("same as rows",
							Numeric,
							Ordinal,
								Set Values( rows )
									
			);
			
dt2&amp;lt;&amp;lt;new column("row number",
							Numeric,
							Ordinal,
								Formula(Row())
									
			);
dt1 &amp;lt;&amp;lt; update(
     with(dt2),
     match(:same as rows=:row number),
     ignore missing,
     add columns from update(none)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Aug 2024 21:05:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782451#M96592</guid>
      <dc:creator>spinup</dc:creator>
      <dc:date>2024-08-18T21:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782453#M96593</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1=New Table( "Table 1",
	Add Rows( 20 ),
	New Column( "x",
		Formula( Random Uniform(0,10) )
	),
	New Column( "y",
		Formula( Random Uniform(0,10) )
	)
);

dt2=New Table( "Table 2",
	Add Rows( 64 ),
	New Column( "x2",
		Formula( floor(row()/8)+1 )
	),
	New Column( "y2",
		Formula( mod(row(),8)+1 )
	)
);


// M2 = dt2 &amp;lt;&amp;lt; GetAsMatrix();
// better - see below
M2 = dt2[0, {"x2", "y2"}];
MD2=kdtable(M2);

dt1 &amp;lt;&amp;lt; New Column( "row_orig",Nominal, Formula( Row() ));
dt2 &amp;lt;&amp;lt; New Column( "row_2",Nominal,Formula(  Row() ));


dt1 &amp;lt;&amp;lt; New Column( "table",Nominal, set each value(1));
dt2 &amp;lt;&amp;lt; New Column( "table",Nominal, set each value(2));
wait(0);

// step by step, for each row in dt1, use MD2 to find the closest position in dt2
dt1 &amp;lt;&amp;lt; new column("row_2",Nominal, set each value(
pos = Matrix({:x, :y});
(MD2 &amp;lt;&amp;lt; K nearest rows( 1, pos))[1][1]));


// concatenate the tables to generate a combined plot
dt2:x2 &amp;lt;&amp;lt; set name("x");
dt2:y2 &amp;lt;&amp;lt; set name("y");
check = dt1  &amp;lt;&amp;lt; Concatenate(dt2);
check &amp;lt;&amp;lt; Graph Builder(
	Show Control Panel( 0 ),
	Variables( X( :x ), Y( :y ), Overlay( :row_2 ), Color( :table ) ),
	Elements(
		Line( X, Y, Row order( 1 ) ),
		Points( X, Y, Overlay( 0 ), Legend( 2 ) )
	),
	SendToReport(
		Dispatch( {}, "400", ScaleBox,
			{Legend Model(
				2,
				Properties( 0, {Marker( "FilledSquare" )}, Item ID( "1", 1 ) ),
				Properties( 1, {Marker( "Circle" )}, Item ID( "2", 1 ) )
			)}
		)
	)
);&lt;/CODE&gt;&lt;/PRE&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="hogi_0-1724015595759.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/67226i82F15169564F2EDD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1724015595759.png" alt="hogi_0-1724015595759.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 12:06:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782453#M96593</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-08-19T12:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782457#M96594</link>
      <description>&lt;P&gt;Thanks for cleaning this up for me&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/26800"&gt;@hogi&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question, can you walk me though what this line of code is doing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-jsl"&gt;&lt;CODE&gt;dt1 &amp;lt;&amp;lt; new column("row_2",Nominal, set each value(pos = Matrix({:x, :y});(MD2 &amp;lt;&amp;lt; K nearest rows( 1, pos))[1][1]));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 00:19:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782457#M96594</guid>
      <dc:creator>shampton82</dc:creator>
      <dc:date>2024-08-19T00:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782459#M96595</link>
      <description>&lt;P&gt;Thanks hogi,&lt;/P&gt;&lt;P&gt;This runs like a champ, however , I had the exact same question as Steve:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you explain the line&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-jsl"&gt;&lt;CODE&gt;dt1 &amp;lt;&amp;lt; new column("row_2",Nominal, set each value(pos = Matrix({:x, :y});(MD2 &amp;lt;&amp;lt; K nearest rows( 1, pos))[1][1]));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Additionally, when I run my version ( reading the tables with four columns ( x, y, data 1, data 2) on Table 1 and ( x2, y2, data 3, data 4)) I get the below alert . I think it is upset because the Table 1, and Table 2 have more than two columns (x, y) which are not in the matrix. But if you explain the line, I think I can figure out the rest! Thanks for the help&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="spinup_0-1724027255837.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/67229i2523F0D5F1DF8D08/image-size/medium?v=v2&amp;amp;px=400" role="button" title="spinup_0-1724027255837.png" alt="spinup_0-1724027255837.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 00:29:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782459#M96595</guid>
      <dc:creator>spinup</dc:creator>
      <dc:date>2024-08-19T00:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782462#M96596</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/15496"&gt;@spinup&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the issue is my code assumed you only had the x and Y values in the table.&amp;nbsp; If you start with your tables that have extra numeric columns then k nearest neighbors is trying to find the closest point for X,Y, A, B vs X, Y, C, D.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think that's why&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/26800"&gt;@hogi&lt;/a&gt;&amp;nbsp;codes works so well if it is only looking at X and Y.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you made the non-X/Y columns character and ran the my second code it would work, you'd just need to change them back to numeric once you joined them.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 01:20:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782462#M96596</guid>
      <dc:creator>shampton82</dc:creator>
      <dc:date>2024-08-19T01:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782476#M96598</link>
      <description>&lt;P&gt;Something like this is what I usually end up with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt1 = New Table("Table 1",
	Add Rows(20),
	New Column("x", Numeric, "Continuous", Formula(Random Normal())),
	New Column("y", Numeric, "Continuous", Formula(Random Normal()))
);

dt2 = New Table("Table 2",
	Add Rows(20),
	New Column("x", Numeric, "Continuous", Formula(Random Normal())),
	New Column("y", Numeric, "Continuous", Formula(Random Normal())),
	New Column("Val", Numeric, Continuous, Formula(Random Normal(2, 100)))
);

m1 = dt1[0, {"x", "y"}];
m2 = dt2[0, {"x", "y"}];

tree = VPTree(m2);
{rows, distances} = tree &amp;lt;&amp;lt; K Nearest Rows(1, m1);

dt1 &amp;lt;&amp;lt; New Column("Nearest", Numeric, Ordinal, Values(rows));
dt1 &amp;lt;&amp;lt; New Column("Distance", Numeric, Ordinal, Values(distances));
dt2 &amp;lt;&amp;lt; New Column("Row", Numeric, Ordinal, Values(1::N Rows(dt2)));


/* Depending on the wanted result, using Update might be better */
dt_result = dt1 &amp;lt;&amp;lt; Join(
	With(dt2),
	By Matching Columns(:Nearest = :Row),
	Drop multiples(0, 0),
	Include Nonmatches(0, 0),
	Preserve main table order(1),
	Output Table("Result")
);

/*
Close(dt1, no save);
Close(dt2, no save);
*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;/SPAN&gt;Join/K Nearest Rows could be done to wrong direction as I didn't verify the results&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 03:43:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782476#M96598</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-08-19T03:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782554#M96611</link>
      <description>&lt;P&gt;To get the matrix with the coordinates, you can use data table subscripting, like Jarmo does in his example:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;row = 0 -&amp;gt; all rows&lt;BR /&gt;columns: x and y&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;coordinates as matrix = dt1[0, {"x", "y"}];&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Aug 2024 11:01:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782554#M96611</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-08-19T11:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782559#M96612</link>
      <description>&lt;P&gt;The Documentation of &lt;FONT face="courier new,courier"&gt;VPTree&lt;/FONT&gt; could be optimized.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;KD Table:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1724065620983.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/67250iA30E109B8C5CDBEB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1724065620983.png" alt="hogi_0-1724065620983.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;KDTable &lt;FONT face="courier new,courier"&gt;&amp;lt;&amp;lt;&amp;nbsp; K nearest rows&lt;/FONT&gt; has two modes:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;default: take the input positions as starting points.&lt;BR /&gt;-&amp;gt; not suitable for us.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;&lt;LI&gt;optional: use a single position as starting point.&lt;BR /&gt;-&amp;gt; yes!&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I calculate this point as &lt;FONT face="courier new,courier"&gt;pos = Matrix ({:x,:y})&lt;/FONT&gt;for every row and supply it as second argument for &lt;FONT face="courier new,courier"&gt;K nearest rows&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The return values are vectors of &lt;FONT face="courier new,courier"&gt;rows&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;distances. &lt;/FONT&gt;With the &lt;FONT face="courier new,courier"&gt;[1][1]&lt;/FONT&gt;, I can first get the &lt;FONT face="courier new,courier"&gt;rows&lt;/FONT&gt;, and then the first (and only) entry.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunatley, there is no mode to provide a set of starting point as input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;VPTree:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;For &lt;FONT face="courier new,courier"&gt;K nearest Rows&lt;/FONT&gt; there is no real documentation in the Scripting INdex, but there is an example right in the definition of VPTree:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_2-1724066253901.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/67252i9205D26EC8537DDF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_2-1724066253901.png" alt="hogi_2-1724066253901.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and there is some documentation in the online help:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_1-1724066227445.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/67251i2158E943485E871A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_1-1724066227445.png" alt="hogi_1-1724066227445.png" /&gt;&lt;/span&gt;&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="hogi_0-1724066636952.png" style="width: 669px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/67253i813324C26E555A8C/image-dimensions/669x17?v=v2" width="669" height="17" role="button" title="hogi_0-1724066636952.png" alt="hogi_0-1724066636952.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;sounds like the same 2 options as for KDTable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt; 's example you can see that VPTree allows a third mode, where a set of positions is provided as a matrix.&lt;/P&gt;&lt;P&gt;This is a bit surprising, but very convenient :)&lt;/img&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;tree = VPTree(m2);
{rows, distances} = tree &amp;lt;&amp;lt; K Nearest Rows(1, m1);
dt1 &amp;lt;&amp;lt; New Column("Nearest", Numeric, Ordinal, Values(rows));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 11:30:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782559#M96612</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-08-19T11:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782560#M96613</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;VPtree &amp;lt;&amp;lt; K Nearest Rows(1, matrix of coordinates);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;nice&amp;nbsp; : ):)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 11:34:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782560#M96613</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-08-19T11:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add data from one table to another table based on the distance</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782564#M96615</link>
      <description>&lt;P&gt;Further Ideas:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;- related wish for 1D:&lt;LI-MESSAGE title="Add fuzzy join / asof merge / join by columns which do not have exact matches" uid="462354" url="https://community.jmp.com/t5/JMP-Wish-List/Add-fuzzy-join-asof-merge-join-by-columns-which-do-not-have/m-p/462354#U462354" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-idea-thread lia-fa-icon lia-fa-idea lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;BR /&gt;I just added a comment to consider higher dimensions.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- In real application cases, there are additinal &lt;U&gt;&lt;STRONG&gt;nominal coodinates&lt;/STRONG&gt;&lt;/U&gt; like lots, wafers, variants. The user has to split the data accordingly and set up separate VPTrees for each "variant". VPTree with &lt;FONT face="courier new,courier"&gt;groupBy&lt;/FONT&gt; will be a logical next step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- On the other hand, instead of just using a neighboring value, the user might prefer to interpolate the input data to get more meaningful values. &lt;LI-MESSAGE title="Group by - sooo useful!!! how about Interpolate?" uid="692434" url="https://community.jmp.com/t5/JMP-Wish-List/Group-by-sooo-useful-how-about-Interpolate/m-p/692434#U692434" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-idea-thread lia-fa-icon lia-fa-idea lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 11:56:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-add-data-from-one-table-to-another-table-based-on-the/m-p/782564#M96615</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-08-19T11:56:09Z</dc:date>
    </item>
  </channel>
</rss>

