穩健的列引用使用 JSL 編寫幾分鐘程式碼後,使用者會對諸如:性別之類的奇怪物件感到疑惑
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
x = :sex
專家使用者對此類列引用有一定的經驗,並且一直在使用它們。
但是:sex 是什麼? 日期:性別更健壯嗎? 在哪裡可以找到相關文件?
讓我們收集並分享一些見解。如果您發現錯誤,請補充您的想法並糾正我的帖子…
我的看法:
自動化和腳本回覆:穩健的列引用在 JSL 中,同一個欄位引用:性別 (或dt:性別 )可以用兩種方式使用:
# 1) 作為對一列的引用
:sex << get name;
Data Table( "Big Class Families" ) << Distribution( Nominal Distribution( Column( :sex ) ));
……以及#2
若要檢索此列中目前行的項目,例如:
【編輯】:不!
“用於列公式——通常可以理解為‘當前行的值’。”
但還有許多其他情況也需要這種類型的性行為。
</CODE></PRE>
<BR />
<P>請注意:在列公式中,以下方法等效。</P>
<PRE><CODE class=" language-jsl">new column("s", formula (:sex));
new column("s", formula (:sex[]));
new column("s", formula (:sex[row()]))
row()=5;
s=:sex; // value of the current row
// other cases:
lag(:sex,1); // value of the previous row
Col Mean(:height, :age)); // mean :height of rows with same :age
要從字串建立這樣的對象,有兩種選擇:
column name = "sex";
col= Column (column name); // for the first one (accessing the column)
val = As Column (column name) // for the second one (accessing the column in formulas)
實際上,還有第三種非常棒的選擇,這是我從@jthi那裡學到的:
the universal column reference = Name Expr(As Column(column name))
它可以像“性別”一樣使用,兩種方法都適用。既可以引用列,也可以存取目前行的條目。
Column() vs As Column() vs datable:column vs dt:As name("column")
回覆:健壯的列引用:性別看起來很脆弱 - 當使用者更改列名時會發生什麼?
Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
x = Name Expr(As column("name"));
Show(Name Expr(x)); // : name
:name << set name("The name");
Show(Name Expr(x)); // :The name
哇,太棒了!一點也不脆弱!
回覆:健壯的列引用當使用者更改資料表?
Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
x = Name Expr(As column("name"));
Show(Name Expr(x));
x[1] = "Marker";
:name << set name("The name");
dt = Open( "$SAMPLE_DATA/Big Class Families.jmp" );
Show(Name Expr(x));
Show(x[1])
:性別這個無辜的變數甚至知道自己實際上屬於哪個資料表。太棒了!
回覆:健壯的列引用現在,讓我們從 1 列轉到 2 列:
myList1 = {:name,:sex,:age};
創建此列表的一個非常複雜且無用的方法是:
myList2 = Eval List({Name Expr(As column(:name)),Name Expr(As column(:sex)),Name Expr(As column(:age))});

回覆:健壯的列引用無用?
當你嘗試執行上述程式碼時,你已經注意到了巨大的差異,而沒有
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
第一行並不關心是否存在開啟的資料表。運行第二行時,JMP 會報錯:

更好的是:當使用第二種方法建立清單時,列引用非常強大。
無論當前資料表如何,JMP 都會轉到日期並使用其中的列:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
myList1 = {:name,:sex,:age};
myList2 = Eval List({Name Expr(As column(:name)),Name Expr(As column(:sex)),Name Expr(As column(:age))});
dt2= Open( "$SAMPLE_DATA/Big Class Families.jmp" );
dt << Select Rows( [1] ) << Delete Rows; // now dt starts with Louise - there is no Katie anymore!
Show(Eval List(myList1), // Katie? why Katie!!!
Eval List(myList2)); // Louise -> works!

它是如何運作的?
Show(Type(myList1[1]), Type(myList2[1]))
提供更多見解:

簡單列表( 我的清單1 )包含“N 艾姆斯 ”,*)
複雜列表( 我的清單2 )包含「列」**)
*) 當評估名稱時,JMP 遵循特定規則來確定該名稱的含義:
https://www.jmp.com/support/help/en/19.0/#page/jmp/rules-for-resolving-names.shtml
在角色中,JMP 將在目前資料表( dt2 ) 中搜尋一列。
**) 對於列,JMP 只需轉到資料表(「日期」)並存取該列。
非常堅固!
回覆:健壯的列引用Name Expr(As column(:col))
太酷了!
回覆:健壯的列引用Column() 在許多情況下都適用,對於列名的格式來說相當靈活。
Distribution(
Continuous Distribution( Column( :Random Normal )),
Continuous Distribution( Column( "Random Normal" )),
Continuous Distribution( Column( :"Random Normal"n )),
Continuous Distribution( Column( "Random Normal"n )),
Process Capability( 0 ) )
回覆:健壯的列引用有趣的是:當要求提供列表時,JSL 函數會傳回名稱列表,而不是列的列表!
Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
colList = Eval List({Name Expr(As column("sex"))});
write(Name Expr(colList[1]), " is a ", // :sex
Type(Name Expr(colList[1])), "\!n"); // Column -> universal & robust
selectedCols = dt << select columns (:sex) << get selected columns;
write(Name Expr(selectedCols[1])," is a ", // : sex
Type(Name Expr(selectedCols[1])), "\!n"); // Name -> fragile
dt << Group Columns(Item Range( :sex, :height ),"myColGroup");
colsFromColumnGroup = dt << get column group("myColGroup");
Write(Name Expr(colsFromColumnGroup[1]), " is a ", // :sex
Type(Name Expr(colsFromColumnGroup[1])), "\!n"); // Name -> fragile

取得列名()和取得列引用()之間的差異:
ColNames = dt << get column names; // default setting: returns names, not Strings
Write(Name Expr(ColNames[3]), " is a ", // sex (more or less the same as :sex)
Type(Name Expr(ColNames[3])), "\!n"); // Name -> fragile
ColRefs = dt << get column references;
Write(Name Expr(ColRefs[3]), " is a ", // Column("sex"
Type(Name Expr(ColRefs[3])), "\!n"); // Column -> robust, but not :sex, see below

現在讓我們來處理該列,然後詢問第 1 行中:性別的值:
//hide the column
:sex << set name("hidden");
// who finds it?
row()=1;
Try(Show(Eval(ColList[1])), print(exception_msg));
Try(Show(Eval(colsFromColumnGroup[1])), print(exception_msg));
Try(Show(Eval(selectedCols[1])), print(exception_msg));
Try(Show(Eval(ColNames[3])), print(exception_msg));
Try(Show(Eval(ColRefs[3])), print(exception_msg));

回覆:健壯的列引用帶回家的信息:
透過學習
myList2 = Eval List({Name Expr(As column(:name)),Name Expr(As column(:sex)),Name Expr(As column(:age))});
我們可以透過以下方式將 JMP 提供的任何列表轉換為強大的列表
ColNames = dt << get column names;
colList = Transform Each({col}, ColNames, Name Expr(As Column (col)));
回覆:健壯的列引用
@Byron_JMP wrote:
Column() 在許多情況下都適用,對於列名的格式來說相當靈活。
Distribution(
Continuous Distribution( Column( :Random Normal )),
Continuous Distribution( Column( "Random Normal" )),
Continuous Distribution( Column( :"Random Normal"n )),
Continuous Distribution( Column( "Random Normal"n )),
Process Capability( 0 ) )
你好@Byron_JMP ,在分配()中使用柱子()可以帶來很多樂趣
Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Distribution(Continuous Distribution( Column( :height )) );
Distribution(Continuous Distribution( Column( "height")) );
列引用、名稱,甚至字串!一切正常。
....直到您嘗試使用在分配命令之外定義的列:
col = Column("height");
Show(col); // shows: it's a column
Distribution(Continuous Distribution(col));
Distribution(Continuous Distribution(Eval(col)));
Distribution(Continuous Distribution(Name Expr(col)));
人們可以嘗試所有這些深奧的“讓我們嘗試所有這些 - 其中一個應該有效” - 表達式處理技巧,但它們都不起作用!
總是相同的提示,但這是什麼意思? ! ?

解決方案非常簡單 - 但如果您在錯誤的地方尋找它,則可能需要花費數小時的時間。
打開之前先自己找解決方案
:mano_con_el_dedo_índice_apuntando_hacia_abajo:
看更多...
Column( :height ) inside
連續分佈()
看起來 like
列(“高度”) in
col = 列(“高度”);
But it is a
命名參數 - like
公式() in
新列(公式(...)).
So the "obvious" solution is: keep the name of the named argument and place the column inside:
Distribution(Continuous Distribution(Column(col)));
回覆:健壯的列引用我的方法要簡單得多。我會根據自己的具體目的精心建立我的清單。有時我會用不同的格式建立多個清單。
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
text = dt << Get Column Names();
quote = dt << Get Column Names( String );
colformat = dt << get column reference();
quote = dt << Get Column Names( String );
show(text, quote, colformat);
返回:
text = {姓名,年齡,性別,身高,體重};
quote = {“姓名”,“年齡”,“性別”,“身高”,“體重”};
colformat = {Column("姓名"), Column("年齡"), Column("性別"), Column("身高"), Column("體重")};
這三種方法通常都可以奏效,即使我必須求助於 eval(parse())
回覆:健壯的列引用基本上,我同意你的觀點。只要採取一些預防措施,名字就不是很危險:
人們可能會爭論在創建列表後重命名列是否明智 - 然後懷疑/抱怨舊名稱不再起作用。
當使用兩個表格時,必須確保正確的資料表是目前資料表()。
與列名相同:
可以假設 JMP 能夠正確處理列名 - 即使包含大寫字母和空格。 [查找連結]
或者人們可以謹慎並遵循一些規則。 (名稱、變數和列名之間沒有衝突;注意空格,...)並且一天中的大部分時間都可以安全生活而不會出現問題。
回覆:健壯的列引用嗨@Byron_JMP ,很挑剔...

取得列名()返回名稱清單;)
回覆:健壯的列引用重要發現—我剛剛編輯了第一篇文章!
我希望我的想法是可以理解的——至少對於像@Craige_Hales這樣的一些用戶來說。
我想,這些用戶也會和我一樣感到驚訝/啟發/喜悅和/或透過確認情況確實如此、提供解釋或進行更正來提供幫助。
到目前為止,我認為作為列(col)是一種檢索當前行值的方法 - 特別是與用於“列訪問”的列(col)相比(您知道,就像在Column(col) << 獲取名稱中一樣)。
具有相反的意思:
每當我將 :col 用於「當前行的值」以外的任何內容時,當我想用變數替換它時,我就不必使用作為列() ,而必須使用另一個,即Column(col)。
[我必須承認,這個名字也讓我感到困惑:
作為列() - 對於執行逆操作的函數,取得的不是列,而是目前行的值?你在開玩笑嗎?
另一個想法:
如果在這種情況下作為列(col)有效,那麼這只是因為 JMP 會自動修正使用者的錯誤 - 或者是因為每個人都使用但沒有人解釋的深奧效果 - 就像在名稱 expr(作為列(col))中一樣
所以,現在我發現之後感覺很舒服:....]
這種解釋肯定是錯的。它是由 JMP 中的一種自動化機制觸發的,這種機制可能遵循以下思路:
因為 column(col)可以存取柱子。
如果對 ( Eval(作為列()...) )i進行了求值,則會轉換為列(col)[]或列(col)[行()] ,可用來存取目前行的值。如果未對其進行求值,而是在其他函數中使用,則會允許存取該列的值。
我為什麼會這麼認為呢?
Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class Families.jmp" );
row()=10;
Lag(:height); // 60
Show(lag(Column ("height"),1)); // Column("height") !!!
Show(lag(As Column ("height"),1)); // 60 !!!
Col Mean(:height); // 6255
Col Mean(:height, :age); // 60.285...
Show(Col Mean(Column ("height"))); // 62.55 (why does it work? another automatism because it is used so often?)
Try(Show(Col Mean(Column ("height"), :age)),Print(exception_msg)); // !!!
Show(Col Mean(As Column ("height"), :age)); // 60.285...
[ https://community.jmp.com/t5/Discussions/Using-numeric-objects-in-a-column-equation/mp/903939/highlight/true#M106270觸發]
回覆:健壯的列引用基於此學習,我有一個具體的問題:
是否有一個全面的概述
- which functions act in the spirit of
Eval(:col), Where(:col=1) and Type(:col) ?
i.e. taking the column :col and 將其解釋為:col[row()] ?
看更多...
rw = Row();
Where( :age == Column( "age" )[rw] );
- ,哪些函數只是將列視為一列- 而無需“免費添加[行] ”?
如Col median(:col)、Lag(:col,1)
哪個群組的成員最多?
回覆:健壯的列引用我認為 Col Mean 在劇本中表現得不好。
但是,如果在資料表的公式列中應用了列公式 Col Mean(:height,:age),則「60.285714286」是第 10 行的值。
如果第 10 行位於具有 Col Mean(;height) 的公式列中,則「62.55」是第 10 行的值。
這將是掩蓋在另一個表中查找值的一種非常好的方法,特別是當該表是私有的時。
回覆:健壯的列引用抱歉,我不確定我是否明白了這一點。
Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" , Private);
col median(dt:height);
vals= dt:height << get values();
vals=dt[0,"height"];
Median(vals);