数据表你好,
我想在 JMP 中比较两个以上的表,查找所有表中都存在的公共列。如果该列的值在每个表中都存在,则返回 1,否则返回 0。对于一些预定义的表,我可以通过 JSL 脚本实现这一点,该脚本会在每个表中添加一个额外的列并返回 0 或 1。
但我希望这个脚本是通用的,这样我就不需要预先定义表名了。它应该像这样:每次运行这个脚本时,它都应该询问我要比较哪些表。
之后,我还希望这个脚本能够让我选择要比较的列。
目前,我正在使用这个脚本。
// Get references to the three tables
dt1 = Data Table("Untitled 9");
dt2 = Data Table("Untitled 10");
dt3 = Data Table("Untitled 11");
// Extract ID values from each table
ids1 = dt1:ID << Get Values;
ids2 = dt2:ID << Get Values;
ids3 = dt3:ID << Get Values;
// Find common IDs manually
commonIDs = {};
For(i = 1, i <= N Items(ids1), i++,
If(Contains(ids2, ids1[i]) & Contains(ids3, ids1[i]),
Insert Into(commonIDs, ids1[i])
)
);
// Function to add indicator column
AddIndicatorColumn = Function({dt},
dt << New Column("PresentInAll",
Numeric,
Formula(If(Contains(commonIDs, :ID), 1, 0))
)
);
// Apply to all tables
AddIndicatorColumn(dt1);
AddIndicatorColumn(dt2);
AddIndicatorColumn(dt3);
编辑(jthi):添加了jsl格式。
选择三个表:Untitled 9、Untitled 10 和 Untitled 11,比较的列是“ID”。
请帮忙解决这个问题。
谢谢

自动化和脚本编写数据访问回复:数据表你的表有多少行?有多少个唯一值?这会影响到如何避免性能问题。
回复:数据表总之,您可以使用“获取数据表列表”和“列表框”来构建用户界面。以下是一个快速入门版本,可以帮助您快速上手。
Names Default To Here(1);
dts = Get Data Table List();
If(N Items(dts) < 2,
Throw("Not enough tables open");
);
run_expr = Expr(
Show(lb_tables << get selected, lb_columns << get selected);
);
tables = dts << get name;
nw = New Window("",
H List Box(
Panel Box("Select tables",
lb_tables = List Box(tables,
<< Set Function(Function({this},
sel = this << get selected;
If(N Items(sel) < 1,
return(0);
);
cols = Datatable(sel[1]) << Get Column Names("String");
lb_columns << Set Items(cols);
))
),
),
Panel Box("Pick Column",
lb_columns = List Box({}, << Set Max Selected(1))
),
Panel Box("Actions",
Lineup Box(N Col(1),
Button Box("OK",
run_expr
),
Button Box("Cancel",
nw << close window;
)
)
)
)
);
Write();
回复:数据表以下是 JSL 的详细内容,它以 Jarmo 的 JSL 为基础并进行了扩展,从而得出了你在最初讨论中展示的结果。
它使用关联数组来查找所有 3 个表中出现的列名的交集,以及所选列中出现的值的交集。
它还利用更新平台将结果移回原来的三个表中。即使对于非常大的数据表,这种方法也应该相当高效。

Names Default To Here( 1 );
dts = Get Data Table List();
If( N Items( dts ) < 2,
Throw( "Not enough tables open" )
);
tables = dts << get name;
// Create the table and column selection window
nw = New Window( "",
H List Box(
// Define the Table selection box
Panel Box( "Select tables",
lb_tables = List Box(
tables,
maxselected( 3 ),
<
<SET function="">
0, lb_columns << Set Items( cols ); pickPBox << visibility( "Visible" ); ); ); ) ) ), ), // Define the column selection box pickPBox = Panel Box( "Pick Column", lb_columns = List Box( {}, Max Selected( 1 ), <
<SET function=""></SET>
</SET>
<BR />