相當於Excel中的索引(Match())我有一些數據想要計算每個唯一 ID 的第一次測量和所有後續測量之間的誤差百分比。我無法弄清楚如何根據其他行列的值從一個單元格獲取數據。這是否需要 JSL,或者我可以像在 Excel 中那樣建立一個公式。
我希望使用公式計算突出顯示的兩列,但由於實際集中有數千行數據,我可以理解它是否必須是腳本,並且值在腳本運行之前是靜態的再次。

任何幫助將不勝感激。
我正在使用 JMP 16。
基礎資料分析與建模回覆:相當於Excel中的索引(Match())您可以使用 Col Min(Row(), :ID) 來獲得最早的測量結果
:Measurement[Col Min(Row(), :ID)]
然後,您可以在單獨的列中使用它,或者僅將其用作單個公式的一部分,該公式將計算您的結果
回覆:相當於Excel中的索引(Match())謝謝,這有效。
但我確實有一個擔憂;如果我想為每個 ID 使用第二個值怎麼辦?
因此,對於 ID == A,「最早測量」欄位中的值為 10.00001。
回覆:相當於Excel中的索引(Match())有很多不同的選項,但它們可能有點難以理解。 「最簡單」的想法是將 Col 統計函數與 if 語句結合起來,if 語句傳回缺失值或您正在尋找的值。
Col Min(If(Col Cumulative Sum(1, :ID) == 2, :Measurement, .), :ID)

使用 Col 統計函數的好處是它們可以很好地與分組列和公式配合使用。
回覆:相當於Excel中的索引(Match())我認為最「類似 JMP」的方法是互動式解決方案,讓 JMP 建立自動化流程(使用增強的日誌/工作流程產生器),然後修復 JMP 建立的腳本留下的「問題」:
由於您已經有了我認為您可以使用的 Order 列,因此建立 Order == 2 的子集。


從子集中將Measurement 欄位重新命名為其他名稱。然後返回原始表並使用 Update 將子集連接回您的表,使用 ID 作為匹配條件列

現在您已經在一列中獲得了第二個順序的測量值。 JMP 將為您編寫以下腳本:
// Select matching cells
Data Table("JMP Example") << Select Where(:Order == 2);
// Subset data table
// → Data Table("Subset of JMP Example")
Data Table("JMP Example") << Select Where(:Order == 2) <<
Subset(Copy formula(0), Selected Rows(1), Selected columns only(0));
// Change column name: Measurement → Measurement_ORDER2
Data Table("Subset of JMP Example"):Measurement << Set Name("Measurement_ORDER2");
// Update data table
Data Table("JMP Example") << Update(
With(Data Table("Subset of JMP Example")),
Match Columns(:ID = :ID),
Add Columns from Update Table(:Measurement_ORDER2),
Replace Columns in Main Table(None)
);
它絕對不是最好的腳本,但它確實有效並給出了正在做什麼的想法。您也可以在開始此流程之前開始工作流程記錄,並建立一個工作流程來自動執行此操作(我個人不使用工作流程,更喜歡增強日誌,但它們可能非常有用,特別是如果您希望自動化某些操作)。由工作流程建構器建立的腳本可能看起來像這樣
Names Default To Here(1);
Workflow 6=function({},
step_name = "Open Data Table: JMP Example.jmp";
//Open Data Table: JMP Example.jmp
Open("$DOWNLOADS/JMP Example.jmp");
step_name = "Select matching cells";
//Select matching cells
Data Table("JMP Example") << Select Where(:Order == 2);
step_name = "Subset data table";
//Subset data table
Data Table("JMP Example") << Select Where(:Order == 2) <<
Subset(Selected Rows(1), Selected columns only(0));
step_name = "Change column name: Measurement → Measurement2";
//Change column name: Measurement → Measurement2
Data Table("Subset of JMP Example"):Measurement << Set Name("Measurement2");
step_name = "Update data table";
//Update data table
Data Table("JMP Example") << Update(
With(Data Table("Subset of JMP Example")),
Match Columns(:ID = :ID),
Add Columns from Update Table(:Measurement2),
Replace Columns in Main Table(None)
);
step_name = "Close Data Table: Subset of JMP Example";
//Close Data Table: Subset of JMP Example
Close(Data Table("Subset of JMP Example"), NoSave);
);
Workflow 6();
一般來說,工作流程建構器所建立的腳本確實與增強日誌所建立的腳本有類似的問題,但工作流程確實有額外的好處(如果您希望這樣考慮它們,我認為它們主要是煩惱,如果除了非常簡單的事情(例如更新引用)之外)。以下是我修改 JMP 所建立的腳本的方法
Names Default To Here(1);
dt = Open("$DOWNLOADS/JMP Example.jmp");
dt << Clear Column Selection << Clear Select;
rows_of_interest = dt << Get Rows Where(:Order == 2);
dt_subset = dt << Subset(Rows(rows_of_interest),
Copy formula(0),
Selected columns only(0),
Invisible
);
Column(dt_subset, "Measurement") << Set Name("Measurement_ORDER2");
dt << Update(
With(dt_subset),
Match Columns(:ID = :ID),
Add Columns from Update Table(:Measurement_ORDER2),
Replace Columns in Main Table(None)
);
Close(dt_subset, no save);
這些也可以使用「更高級」的 JSL 來完成,但通常如果您想使用公式並避免 JSL,我不會使用它們。唯一使用這些的情況是如果您需要速度,即使在這種情況下,除非您優化它們,否則它們有時可能會變慢。這是使用 JSL 的一個選項,並帶有一些註釋來解釋
看更多...
Names Default To Here(1);
dt = Open("$DOWNLOADS/JMP Example.jmp");
// Get all IDs into a list using data table subscripting
ids = dt[0, "ID"];
// Get all unique IDs using Summarize (there are many other methods)
// Note that Summarize will change numeric values to strings (doesn't matter in this case)
Summarize(dt, uniq_ids = By(:ID));
// We can loop over the unique IDs while collecting results
// I will store results to Associative Array as it is efficient method and easy to access
aa_idpos = Associative Array();
aa_meas = Associative Array();
idx_of_interest = 2;
For Each({cur_id}, uniq_ids,
// We can use Loc to find specific ID from a list of IDs
cur_idx = Loc(ids, cur_id);
// From this we can pick second index for example and store it to our aa
// Note: Usually you want to check that there is at least two items if you do this
aa_idpos[cur_id] = cur_idx[2];
// You could also get the Measurement value instead
// (I prefer index as then I can access value from any of the columns easily)
aa_meas[cur_id] = :Measurement[cur_idx[idx_of_interest]];
);
// Show(aa_idpos);
// Then you can basically do whatever you want with these
// Fill them into the table for example by using Formula OR For Each Row
// Formula tends to be faster if you just need one column
new_col = dt << New Column("Second Meas by ID", Numeric, Continuous, Formula(
aa_meas[:ID]
));
// aa_meas WON'T be evaluated unless you specifically do it, so either remove the formula
// or evaluate it using eval(evalexpr()) / eval(substitute())
dt << run formulas;
new_col << Delete Formula();
<BR />/*
// or evaluation (one option, there many other options (local variables, not worrying about the scope, ...))
new_col = Eval(EvalExpr(
dt << New Column("Second Meas by ID", Numeric, Continuous, Formula(
aa = As Constant(Expr(aa_meas));
aa[:ID]
));
));<BR />*/
回覆:相當於Excel中的索引(Match())如果您知道您的資料是有序的,就像它們在範例資料表中一樣,並且假設總是有第二個值,那麼
:Measurement[Col Min( Row(), :ID ) + 1]
是使用該系列中第二行的非常簡單的方法。
回覆:相當於Excel中的索引(Match())按照@txnelson的建議,您也可以使用它:

:Measurement[Col Maximum( If( :Order == 2, Row() ), :ID )]
這將傳回每個 ID 的第二個測量值。
@JasonWS
我整理了這個 PowerPoint 來向 JMP 新使用者介紹如何在 Excel 中使用 vlookup 進行操作。希望它也能有所幫助。
史蒂夫
希望有幫助!
回覆:相當於Excel中的索引(Match())如果您想要聚合多個條目以供參考,或者如果存在排除的行,則該主題會變得更加複雜。
除此之外,如果您在日常工作中經常應用此類計算,您不想一次又一次/手動建立公式。
願望清單新公式欄/分佈中有一個願望:「標準化」 。
但其他用戶的興趣相當低 - 只有 2 個榮譽...
所以,我聽從了@mia_stephens的建議

……並開發了我自己的插件。它可以在市場中找到:
https://marketplace.jmp.com/appdetails/Normalization+GUI
AddIn 提供了一個使用者介面來自動產生此類計算。
除了許多其他選項之外,還有“first”、“last”和“N-1”選項。

也可以使用第二個條目進行標準化。
只需啟用

並使用 Rank/Order 列,如@shampton82所解釋的:

最後,公式將如下所示:

與@shampton82的方法非常相似:
它使用Col ...聚合將參考值分發到其他行。
一個微妙的區別:它分配的是值而不是行索引。