怎样用脚本实现将数据表的内容与第二个表中内容匹配的字符数量,不考虑顺序 、相符合数据最多的返回第二个表的行号。
我只会编写简单的循环比较。
如果要比较的字符串数量很多时、怎样才能较快速。
谢谢!
If no duplication is allowed you could try using associative arrays and their set operations:
Names Default To Here(1); dt = New Table("demo", Add Rows(4), New Column("A", Character, "Nominal", Set Values({"KDBAC", "FLGHEK", "ONLCQR", "WVTZXR"})), New Column("B", Character, "Nominal", Set Values({"ROMNLQ", "DFBACE", "LKGHJK", "WVTZYX"})) ); // Create lookup associative array, with row number as key and value as associative array with // keys as characters in row. This will be used in union operations aa_lookup = Associative Array(); For Each({val, idx}, dt:B << get values, aa_lookup[idx] = Associative Array(Eval List(Words(val, ""))); ); // Create collection column dt << New Column("C", Numeric, Continuous); For Each Row(dt, best_match = 0; max_row = .; For Each({{key, val}}, aa_lookup, cur_aa = Associative Array(Eval List(Words(:A, ""))); cur_aa << Intersect(val); cur_match = N Items(cur_aa); If(cur_match > best_match, best_match = cur_match; max_row = key; ); ); :C = max_row; );
For example,
string for the first table
"KDBAC" "FLGHEK" "ONLCQR" "WVTZXR"
String for the second table
"ROMNLQ" "DFBACE" "LKGHJK" "WVTZYX"
Can there be duplicated characters in the strings?
JMP Pro 15.2,
Thank jthi!
If you are using JMP15 you have to change For Each to For-loop.