JMP 如何計算列公式?@txnelson只是在內部使用summarize()作為常數:
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 ) );
非常有趣的方法!
對於as Constant ,腳本索引提供了一個範例
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 只是解決設定每個 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 如何計算列公式?您的意思是我在這裡提到的問題Bug 在循環中使用設定每個值、具有相同列名的表和 col 統計函數的組合嗎?
回覆:JMP 如何計算列公式?啊,對了,就是這個。
因此,不僅<< 設定每個 value()受到影響 - Formula()也會受到影響。
很幸運昨天我找不到你的貼文。
我不敢在讀完它後<< 設定每個 value() ...
也許:不是作為解決方法,而是作為交叉檢查。
有趣的是:就我而言,沒有涉及 col 統計(如colrank() )。
也許 JMP 知道該程式碼的目的是創建一個; )