數據表你好,
我想在 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 />