简体   繁体   English

JMP脚本:为什么我的列数据没有发送到Function中?

[英]JMP Scripting: Why doesn't my column data get sent into a Function?

I am creating a JSL script for some of my datatables and need my function to act on a column. 我正在为某些数据表创建JSL脚本,并且需要我的函数对列进行操作。

I can get the function to act on the column during a plotting event, but not with standard operations. 我可以让函数在绘图事件中对列起作用,但不能使用标准操作。

Here's an example that works. 这是一个有效的示例。 This acts on the current datatable and plots up the Distribution for :Column1 , which happens to be Nominal Character with 4 unique items in it. 这作用于当前数据表并绘制:Column1的分布,该分布恰好是其中包含4个唯一项的名义字符。

a = Function(
        {col},                 // Function parameters
        {Default Local},       // Local variables
        Distribution(
            Nominal Distribution(
                Column( col ),
                Horizontal Layout( 1 ),
                Vertical( 0 )
            );
        );
    );

dt = Current Data Table();
a(Expr(:Column1));

Note the Expr() around :Column1 . 请注意:Column1周围的Expr() Without this, the Distribution function does not work. 没有此功能,分发功能将不起作用。


What I'm trying to do is the following, but it doesn't work. 我想做的是以下操作,但是不起作用。 What it should do is show the number of unique items in :Column1 . 它应该做的是显示:Column1中唯一项的数量。

a = Function(
        {col},                 // Function parameters
        {Default Local},       // Local variables
        retval = associative array(col);
        Show(nitems(retval));
    );

dt = Current Data Table();
a(Expr(:Column1));

    Returns in Log Window:
    N Items(retval) = 0;        // Should be 4

If I run the script without trying to wrap it in a function, then it works just fine: 如果我运行脚本时没有尝试将其包装在函数中,那么它将正常工作:

retval = associative array(:Column1);
Show(nitems(retval));

    Returns in Log Window:
    N Items(retval) = 4;        // My column happens to have 4 unique entries in it.

I'm fairly certain that my issue has something to do with namespace inside the function, but I can't seem to figure it out. 我相当确定我的问题与函数中的名称空间有关,但我似乎无法弄清楚。 Does anyone have any suggestions? 有没有人有什么建议?

It is (from what I've seen) just an issue with the scoping operator : in :Column1. (从我所看到的),它只是作用域运算符中的一个问题::Column1中。

Try using 尝试使用

a = Function(
    {col},                 // Function parameters
    {Default Local},       // Local variables
    retval = associative array(col<<Get Values)<<Get Keys;
    Show(nitems(retval));
);

dt = Current Data Table();
a(column(dt, "Column1"));

it returned 它回来了

N Items(retval) = 9; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM