用於檢查列的行中是否包含任何項目清單的公式Mac 版 JMP
版本 17.2.0 (701896)
我有一列“資料”,其中包含 number_number 行,如下所示:
1_3
3_7
6_5
……
我想測試此列以查看某些行是否包含值列表中的值,然後標記或標記包含的行。
我知道我可以建構一個像這樣的複雜公式:
If( :Die X_Y == "3_9" | :Die X_Y == "3_4",
1,
0
)
但這對於檢查一長串不同值來說非常費力。我希望能夠貼上要在公式中檢查的值列表,以空格或逗號分隔。
我找到了「 包含項目」功能。它適用於一項,但幫助條目沒有提供有關如何建立“列表”選項的任何見解。我嘗試了這個(將可選分隔符指定為空格):
If( Contains Item( :Die X_Y, "3_4 3_9", " " ),
"exclude",
"not exclude"
)
還有這個:
If( Contains Item( :Data, "3_4,3_9", "," ),
"exclude",
"not exclude"
)
我知道預設分隔符號是逗號,但希望強制查找任何有效的分隔符號。 Contains Item 函數均未傳回所需的行為(如果存在符合則傳回邏輯 1,如果不符合則傳回 0)。如果有更好的功能可以使用請指教。
這是我希望能夠解決的普遍問題——檢查列以查找與長項目清單的匹配項。
謝謝
自動化和腳本編寫macOS回覆:用於檢查某一列的行中是否包含任何項目清單的公式一個很好的副作用:
這次討論讓我想到:
包含是否也會增加科爾聚合的速度?
不管你信不信,它確實存在。哇,它確實存在! ! !
https://community.jmp.com/t5/Discussions/How-do-I-use-the-Col-Maximum-Formula-with-a-quot-where-quot/mp/810363/highlight/true#M99287
有沒有什麼線索可以解釋為什麼字元比較如此緩慢?
回覆:檢查列的行中是否包含任何項目清單的公式閱讀內容是:3個參數
- x - 字串
- 3個選項:
- 要搜尋的項目
- 多個項目的清單 - 其中一個下擺是否匹配
- 搜尋模式 - 可選參數:將 x 分割成單字的分隔符
@datanaut寫道:
因此(根據我的簡單理解)x 或 {list} 可以包含要搜尋的單字或要與之比較的單字清單。
-> 是的。
包括一個列,如 Jarmo 的範例中所示
對於列公式,這總是可能的,請按照以下想法:
對於每一行,JMP 將自動取得對應行中的列條目。
當您使用公式編輯器時,您一直在執行此技巧 - 只是沒有註意到。
回覆:檢查列的行中是否包含任何項目清單的公式感謝@jthi 、 @txnelson 、 @hogi和@mmarchandFSLR對我的問題的回答和努力。
Jarmo 發現了我的問題——切換公式中的清單和項目。感謝您提供一些說明正確用法的程式碼。
回覆:“文檔有點缺乏”
我同意。腳本索引中的說明和範例對我來說確實有點含糊。這是腳本索引的條目:
」
包含項目(x, <物品| {清單} |圖案>、<分隔符>)
……
Returns a Boolean that indicates whether the word (物品), one of a list of words (清單), or pattern (圖案) matches one of the words in the text represented by x. Words are delimited by the characters in the optional quoted delimiter (分隔符) string. A comma is the default delimiter. Blanks are trimmed from the ends of each extracted word from the input text string (x).
"
因此(根據我的簡單理解)x 或 {list} 可以包含要搜尋的單字或要與之比較的單字清單。再舉幾個例子,顯示一些替代方案,其中包括 Jarmo 範例中的列,可能有助於澄清。
我已經把解決方案投入使用了!再次感謝。
回覆:檢查列的行中是否包含任何項目清單的公式啊,太好了!
一開始我對Where()有很糟糕的經歷 - 但不記得為什麼。
也許我使用了錯誤的語法 - 或者問題同時得到了解決...
回覆:檢查列的行中是否包含任何項目清單的公式我認為值得補充的是,Where() 函數比 < 快得多(> 一個數量級!) <<>名稱預設為此處( 1 ); dt = 資料表( "SATByYear" );顯示( N 行( dt ) ); //N 行(dt) = 21245376;現在 = HP 時間(); dt << SelectWhere( :State == "威斯康辛州" | :State == "阿拉巴馬州" );等待(0);總計 = HP Time() - 現在;列印(“<
回覆:檢查列的行中是否包含任何項目清單的公式抱歉,我在之前的運行中錯過了 wait() - 這會反轉答案 1 ...並導致 #3、#4 和 #5 的新可能性
新發現:
- 包含項目() 使用@jthi的語法更快 - v2 更慢
- 選擇哪裡()透過替換它變得更快取得行 where() + 選擇行()。
- 透過將字串比較替換為contains item() , SelectWhere()會顯著(!!)更快。
- 結合(2)和(3)是相當可比的
- ……也適用於更大的數據集。

看更多...
names default to here(1);
dt = Open( "$SAMPLE_DATA/Wafer Stacked.jmp" );
New Column( "x_y",
Character,
Formula( Concat Items( {Char( :X_Die ), Char( :Y_Die )}, "_" ) )
);
wait(0);
t0=hptime();
New Column( "contains item",
Character,
Formula( If( Contains Item( "1_3 3_9", :x_y, " " ), "exclude", "not exclude" ) )
);
dt << run formulas();
t= (hptime()-t0)/1000000;
print("formula - contains item", t);
t0=hptime();
New Column( "contains item v2",
Character,
Formula( If( Contains Item( :x_y, {"3_1","4_4"}) , "exclude", "not exclude" ) )
);
dt << run formulas();
t= (hptime()-t0)/1000000;
print("1) formula - contains item v2", t);
t0=hptime();
New Column( "get rows where",
Character,
set each value("not excluded") );
myrows=[];
for each( {compare}, {"3_1","4_4"},
myrows = V concat to (myrows, dt << get rows where(:x_y == compare));
);
dt << select rows(myrows); // just for fun - it's fast
dt[myrows,"get rows where"] = Repeat({"excluded"},n items(myrows) );
t= (hptime()-t0)/1000000;
print("2) get rows where", t);
t0=hptime();
for each( {compare}, {"3_1","4_4"},
dt<<SELECT where=""> names default to here(1);
dt = Open( "$SAMPLE_DATA/Wafer Stacked.jmp" );
New Column( "x_y",
Character,
Formula( Concat Items( {Char( :X_Die ), Char( :Y_Die )}, "_" ) )
);
wait(0);
t0=hptime();
New Column( "contains item",
Character,
Formula( If( Contains Item( "1_3 3_9", :x_y, " " ), "exclude", "not exclude" ) )
);
dt << run formulas();
t= (hptime()-t0)/1000000;
print("formula - contains item", t);
t0=hptime();
New Column( "contains item v2",
Character,
Formula( If( Contains Item( :x_y, {"3_1","4_4"}) , "exclude", "not exclude" ) )
);
dt << run formulas();
t= (hptime()-t0)/1000000;
print("1) formula - contains item v2", t);
t0=hptime();
New Column( "get rows where",
Character,
set each value("not excluded") );
myrows=[];
for each( {compare}, {"3_1","4_4"},
myrows = V concat to (myrows, dt << get rows where(:x_y == compare));
);
dt << select rows(myrows); // just for fun - it's fast
dt[myrows,"get rows where"] = Repeat({"excluded"},n items(myrows) );
t= (hptime()-t0)/1000000;
print("2) get rows where", t);
t0=hptime();
for each( {compare}, {"3_1","4_4"},
dt<</SELECT> <SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1731305493836.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="hogi_0-1731305493836.png" style="width: 400px;"><span class="lia-inline-image-display-wrapper" image-alt="hogi_0-1731305493836.png" style="width: 400px;"><img src="https://us.v-cdn.net/6038925/uploads/images/70019i116F7A07829AD82B/hogi_0-1731305493836.png" role="button" title="hogi_0-1731305493836.png" alt="hogi_0-1731305493836.png" /></span></SPAN></SPAN>
回覆:檢查列的行中是否包含任何項目清單的公式將其添加到提示和技巧 - JMP/JSL 的最佳實踐
#4 令人驚訝。此刻,我想說:

回覆:檢查列的行中是否包含任何項目清單的公式感謝您的評論。
深入挖掘 - 實際上它不是contains item與SelectWhere 。
一些發現:
- 使用反向“v2”語法包含 item()更快
- 選擇哪裡()透過替換它變得更快取得行 where() + 選擇行()。
- 透過將字串比較替換為contains item() , SelectWhere() 的速度顯著加快。
- 結合 (2) 和 (3) 使其...比 (2) 慢 2 倍 (?!?!)
- 因此,獲勝者(對於該數據集)是#2:
總共:

細節:
看更多...names default to here(1);
dt = Open( "$SAMPLE_DATA/Wafer Stacked.jmp" );
New Column( "x_y",
Character,
Formula( Concat Items( {Char( :X_Die ), Char( :Y_Die )}, "_" ) )
);
t0=hptime();
New Column( "contains item",
Character,
Formula( If( Contains Item( "1_3 3_9", :x_y, " " ), "exclude", "not exclude" ) )
);
dt << run formulas();
t= (hptime()-t0)/1000000;
print("formula - contains item", t);
t0=hptime();
New Column( "contains item v2",
Character,
Formula( If( Contains Item( :x_y, {"3_1","4_4"}) , "exclude", "not exclude" ) )
);
dt << run formulas();
t= (hptime()-t0)/1000000;
print("1) formula - contains item v2", t);
t0=hptime();
New Column( "get rows where",
Character,
set each value("not excluded") );
myrows=[];
for each( {compare}, {"3_1","4_4"},
myrows = V concat to (myrows, dt << get rows where(:x_y == compare));
);
dt << select rows(myrows); // just for fun - it's fast
dt[myrows,"get rows where"] = Repeat({"excluded"},n items(myrows) );
t= (hptime()-t0)/1000000;
print("2) get rows where", t);
t0=hptime();
for each( {compare}, {"3_1","4_4"},
dt<<SELECT where="">names default to here(1);
dt = Open( "$SAMPLE_DATA/Wafer Stacked.jmp" );
New Column( "x_y",
Character,
Formula( Concat Items( {Char( :X_Die ), Char( :Y_Die )}, "_" ) )
);
t0=hptime();
New Column( "contains item",
Character,
Formula( If( Contains Item( "1_3 3_9", :x_y, " " ), "exclude", "not exclude" ) )
);
dt << run formulas();
t= (hptime()-t0)/1000000;
print("formula - contains item", t);
t0=hptime();
New Column( "contains item v2",
Character,
Formula( If( Contains Item( :x_y, {"3_1","4_4"}) , "exclude", "not exclude" ) )
);
dt << run formulas();
t= (hptime()-t0)/1000000;
print("1) formula - contains item v2", t);
t0=hptime();
New Column( "get rows where",
Character,
set each value("not excluded") );
myrows=[];
for each( {compare}, {"3_1","4_4"},
myrows = V concat to (myrows, dt << get rows where(:x_y == compare));
);
dt << select rows(myrows); // just for fun - it's fast
dt[myrows,"get rows where"] = Repeat({"excluded"},n items(myrows) );
t= (hptime()-t0)/1000000;
print("2) get rows where", t);
t0=hptime();
for each( {compare}, {"3_1","4_4"},
dt<</SELECT>
回覆:檢查列的行中是否包含任何項目清單的公式我做了一些計時測試,將 Jarmo 的解決方案與我的解決方案進行比較,並且“包含項目”解決方案比“選擇位置”解決方案快得多。
回覆:檢查列的行中是否包含任何項目清單的公式Usually in cases like this I tend to use Words() to split the string into a list and then compare using Contains() (or in some rare cases Contains Item()). But Contains Item() should also work and you just seem to have your parameters in incorrect order</CODE></P>
<PRE><CODE class=" language-jsl">New Table("Untitled",
Add Rows(3),
Compress File When Saved(1),
New Column("Column 1", Character, "Nominal", Set Values({"1_3", "3_7", "6_5"})),
New Column("Column 2",
Character,
"Nominal",
Formula(
If(Contains Item("1_3 3_9", :Column 1, " "),
"exclude",
"not exclude"
)
),
Set Selected
)
)

腳本索引中的第二個範例


或 JSL 語法參考有 okeish 範例https://www.jmp.com/support/help/en/18.0/#page/jmp/character-functions-2.shtml?os=win&source=application#ww6166335但文件有點缺乏。
回覆:檢查列的行中是否包含任何項目清單的公式這是我要採取的方法
names default to here(1);
dt=current data table();
dt << clear select;
find = {"3_1","4_4"};
for each( {compare}, find,
dt<<SELECT where="">
Once the rows are selected, then excluding, deleting etc. can be done.</SELECT>