稳健的列引用使用 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 中的一种自动化机制触发的,这种机制可能遵循以下思路:
因为列(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);