用于检查某一列的行中是否包含任何项目列表的公式JMP对于Mac
版本 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; now = HP Time(); dt << 选择其中(:State ==“Wisconsin”|:State ==“Alabama”); 等待(0); total = HP Time() - now; 打印(“<
回复:用于检查某一列的行中是否包含任何项目列表的公式抱歉,我在之前的运行中漏掉了 wait() - 这会反转答案 1 ... 并导致 #3、#4 和 #5 的新可能性
新发现:
- 包含 item() 使用@jthi的语法更快 - v2 较慢
- 选择其中()用它替换会更快获取行 where() + 选择行()。
- 通过使用包含 item()替换字符串比较, Select Where() 的速度会显著 (!!) 加快。
- 结合 (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 的最佳实践
第四点令人惊讶。目前,我会说:

回复:用于检查某一列的行中是否包含任何项目列表的公式谢谢你的评论。
深入挖掘 - 实际上它并不包含项目与Select Where 。
一些发现:
- 使用逆“v2”语法,Contains item()速度更快
- 选择其中()用它替换会更快获取行 where() + 选择行()。
- 通过使用包含项 ()替换字符串比较,选择 Where() 的速度会显著加快。
- 而将 (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>