在 JSL 中为子集指定列名的推荐格式是什么?在 JSL 中创建子集表时,可以最简单地在名称前用冒号字符指定列名,如:高度. 但是,如果该名称有破折号 ( '-' ) 中的字符,那是行不通的。 但我发现在名称周围添加引号可以使其正常工作。 下面的完整脚本演示了这两种方法(尽管大类.jmp不包含任何带破折号的列名)。
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
scrName = "Col name test script";
dt << New Script( // (use of 'New Script' gets script written to data table.)
scrName,
//---- create subset with StartTime and given FOMs ----
dt = Current Data Table();
dt_subset = dt << Subset(
Output Table( "Subset of Big Class" ),
All Rows,
Columns(
:name, // not in quotes.
:"height", // in quotes -- required if col name contains '-'.
:"weight" // in quotes -- required if col name contains '-'.
);
);
);
// run script to generate graph.
dt << Run Script( scrName );
并且,根据需要,该脚本被添加到名称为 JMP 的表中列名测试脚本. 并从 JMP 表中执行该脚本(通过选择其绿色箭头)正确地重新生成子集表。 到目前为止,一切都很好。
但是如果您想进入并开始编辑该脚本(通过双击脚本名称并打开编辑器),就会发生有趣的事情。 在这种情况下,从脚本编辑器中按原样运行脚本无法将引用的列名称添加到子表。

查看脚本,双引号似乎导致列名被视为空作为专栏规格。 (很奇怪脚本从绿色箭头运行正常,但在脚本编辑器中却不行;也许它以一种方式在内部保存,但以不同的方式呈现给编辑器??)
无论如何,我的问题是:是否有推荐的方法来指定子集列名称,以防止名称中出现特殊字符(如破折号),但仍然能够使用脚本编辑器来开发和调试脚本? (我实际上正在生成新脚本以编程方式编写代码,因此我无法提前知道名称中是否存在任何特殊字符。)我在 Mac OS 上运行 JMP 14.3.0。
回复:在 JSL 中为子集指定列名的推荐格式是什么?是的,这似乎让事情运作良好。 非常感谢,吉姆!
为了完整起见,结果如下。
首先,将脚本保存到的脚本大类.jmp数据表:
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column("Height / Weight", Formula(:height / :weight));
dt << New Column("Height-Weight", Formula(:height / :weight)); // using '-'.
scrName = "Col name test script";
dt << New Script( // (use of 'New Script' gets script written to data table.)
scrName,
// create subset.
dt = Current Data Table();
dt_subset = dt << Subset(
Output Table( "Subset of Big Class" ),
All Rows,
Columns(
:name,
:Name("height"),
:Name("weight"),
:Name("Height / Weight"),
:Name("Height-Weight")
);
);
);
// run script to create subset.
dt << Run Script( scrName );然后,打开新创建的脚本大类.jmp :

而且,与以前不同的是,当我从此窗口运行此脚本时,它会按预期运行。
回复:在 JSL 中为子集指定列名的推荐格式是什么?引用其中包含特殊字符的列名的正确方法是使用 :Name() 函数
names default to here(1);
dt=open("$SAMPLE_DATA/big class.jmp");
dt << new column("Height / Weight", formula(:height / :weight));
colList = dt << get column names();
show( colList );
/*
colList = {name, age, sex, height, weight, Name("Height / Weight")};
*/
dt << Distribution( Continuous Distribution( Column( colList[6] ) ) );
show(:Name("height / weight")[1]);