cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Jackie_
Level VI

Search the string in Column and copy the numeric value in 2nd column

I have an Excel Worksheet consisting of two columns, one columns has strings with person name and other column contain age of the person. I have almost a list of 500 person. Is there any way I can automate it?Like using script to assign age based on the person name ?

 

 

 

11 REPLIES 11
jthi
Super User

Re: Search the string in Column and copy the numeric value in 2nd column

If I understand correctly what you want to do (basically join by minimum distance) there are quite a few ways of doing this (kdtable, vptree, loc, distance, addins, ...). Below is one example

Names Default To Here(1);

dt_lookup = New Table("Untitled",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([3.8, 4.8, 4])),
	New Column("Column 2", Numeric, "Continuous", Format("Best", 12), Set Values([50, 52, 51]))
);

dt = New Table("Untitled",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([3.801, 4.801, 4.000, 3.7, 4.802, 4.799]))
);

lookup_values = Column(dt_lookup, "Column 2") << get values;
search_values = Column(dt_lookup, "Column 1") << get values;

dt << New Column("Column 2", Numeric, Continuous, << Set Each Value(
	As Constant(tab = KDTable(search_values););
	{rows, dist} = tab << K nearest rows(1, Matrix(:Column 1));
	lookup_values[rows[1]];
));

 

Below are some demonstrations for other options using matrices

Names Default To Here(1);
lookup_values = [50, 52, 51];
search_values = [3.8, 4.8, 4];
search_val = 4.3;

// These should return row from dt_lookup
kdt = KDTable(search_values);
{kd_rows, kd_dist} = kdt << K nearest rows(1, Matrix(search_val));

vpt = VPTree(search_values);
{vp_rows, vp_dist} = vpt << K nearest rows(1, Matrix(search_val));

dist = Distance(search_values, Matrix(search_val));
lmin_dist = LocMin(dist);

abs_calc = Abs(search_values - search_val);
lmin_abs = LocMin(abs_calc);

show(dist, lmin_dist, abs_calc, lmin_abs, kd_rows, kd_dist, vp_rows, vp_dist);

 
-Jarmo
Craige_Hales
Super User

Re: Search the string in Column and copy the numeric value in 2nd column

interpolate( ) would also be a good choice. 

Craige