JMP 如何评估列公式?@txnelson只是在内部使用summary()作为常量:
https://community.jmp.com/t5/Discussions/Alphabetical-Ranking-of-Nominal-Data/mp/822725/highlight/true#M100245
As Constant( Summarize( theLevels = by( :age ) ) );
Contains( theLevels, Char( :age ) );
非常有趣的方法!
对于常量,脚本索引提供了示例
Names Default To Here( 1 );
New Table( "As Constant Demo Table 1",
Add Rows( 10 ),
New Column( "Non-Constant", Formula( Random Uniform() ) ),
New Column( "Constant", Formula( As Constant( Random Uniform() ) ) )
);
this is easy to understand - As Constant( Random Uniform() ) is executed just once and the return value is used for the other rows.
The thing that puzzled me: The return value of 总结 is empty and actually, it's theLevels which we are interested in.
所以,真正的诀窍是
作为常量: “只执行一次” !
非常有用!
可用于:
as constant("JMP just started to evaluate column xyz");
让我们将这个技巧用于另一个应用:打开辅助数据表。
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column( " col",
Formula(
as constant (
dt = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
nr = N Rows( dt );
);
Eval( (EvalExpr(myrows= dtsum << get rows where( :age == Expr(dt:age[row()])))));
Print(:age, myrows);
dtsum[myrows, 2]
)
);
但这并不像我想象的那么容易......
嗯,已经很晚了——我不知道为什么:

自动化和脚本回复:JMP 如何评估列公式?下一个问题——因此也是这篇文章的标题:
为什么当我关闭dtsum时 JMP 会删除条目?
Try(close(dt, nosave));
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Data Table( "Big Class" ) << Sort(
By( :age, :height ),
Replace Table
);
dt << New Column( " col",
Formula(
local({tmp,myAge},
as constant (
dt0 = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
//dtsum:age << set name(age2);
nr = N Rows( dt0 );
);
myage = dt:age[row()];
Eval (Eval Expr(myrows = dtsum << get rows where( :age == Expr(myAge))));
Print(myRows);
tmp = contains(dtsum[myrows,2], :height);
if(row()==nr, dt<< runformulas();wait(1);close(dtsum, noSave);Caption("done"));
tmp
)));回复:JMP 如何评估列公式?问题 1 可以通过以下方式修复:
dt << New Column( " col",
Expression,
set each value (
local({tmp,myAge},
as constant (
dt0 = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
//dtsum:age << set name(age2);
nr = N Rows( dt0 );
);
myage = dt:age[row()]; // save as variable and use later here ↘:backhand_index_pointing_down:</img>
Eval (Eval Expr(myrows = dtsum << get rows where( :age == Expr(myAge))));
dtsum[myrows,2]
)));回复:JMP 如何评估列公式?哇,第二个问题非常令人惊讶,它可以通过以下方式修复
//dense rank - with groupby
dt << New Column( " col",
set each value( // <- the first change is here
local({tmp,myAge},
as constant (
dt = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
//dtsum:age << set name(age2);
nr = N Rows( dt );
);
myage = dt:age[row()];
Eval (Eval Expr(myrows = dtsum << get rows where( :age == Expr(myAge))));
tmp = contains(dtsum[myrows,2],dt:height); // <- the second change is here : use dt:height instead of :height to force JMP to use the right table!
if(row()==nr, close(dtsum, noSave));
tmp
)));这也解决了以前方法中多个“0”条目的问题。
因此,问题的核心不是:
如果表 dtsum 关闭,为什么 JMP 会删除 dt 中的值?
实际问题是:
为什么 JMP 在计算数据表dt的条目时使用dtsum:height而不是dt:height ?
开放问题:为什么 dt:height 只修复set each value()的问题,而不是formula()的问题
回复:JMP 如何评估列公式?啊,
dt << New Column( "dense rank_ grouped by",
Character,
formula (
local({tmp,myAge},
as constant (
dt = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
//dtsum:age << set name(age2);
nr = N Rows( dt );
);
rw = row();
myage = dt:age[row()];
Eval (Eval Expr(myrows = dtsum << get rows where( dtsum:age == Expr(myAge)))); // <- use dtsum:age !!!
tmp = contains(dtsum[myrows,2], dt:height[rw]); // <- use dt:height !!!!
if(row()==nr, close(dtsum, noSave));
tmp
)));
@jthi ,我记得,你不久前遇到过类似的问题——如果两个表的列名重叠,就会发生冲突。
当我找到它时我会添加链接...
回复:JMP 如何评估列公式?您是指我在此处提到的问题:在循环内使用设置每个值、具有相同列名的表和 col 统计函数的组合时出现的 Bug吗?
回复:JMP 如何评估列公式?啊,对了,就是这个。
因此,不仅<<设置每个值()会受到影响 - formula()也会受到影响。
幸亏我昨天没能找到你的帖子。
读完它之后,我不敢<<设置每个值() ......
也许:不是作为一种解决方法,而是作为一种交叉检查。
有趣的是:就我而言,没有涉及 col 统计数据(例如col rank() )。
也许 JMP 知道该代码旨在创建一个;)