简体   繁体   English

使用其他列中的if条件在JMP中创建新列

[英]Creating a new column in JMP using an if condition from another column

I am very new in JMP so I am still feeling around. 我在JMP中非常陌生,所以我仍然感觉良好。 I want to create a new column called "Status" in JMP. 我想在JMP中创建一个名为“状态”的新列。 This status is character and depends on the value of the column "Grade". 此状态为字符,并取决于“等级”列的值。 If the value of the entry in column "Grade" is zero, the value of the entry in column "Status" should be "fail". 如果“等级”列中条目的值为零,则“状态”列中条目的值应为“失败”。 If the "Grade" value is greater than 100, the entry in column "Status" should be "invalid". 如果“等级”值大于100,则“状态”列中的条目应为“无效”。 If the :Grade" value is less than 0, the "Status" value should be "invalid". This should be simple. But somehow, my script won't work: 如果:Grade“值小于0,则” Status“值应为” invalid“。这应该很简单。但是以某种方式,我的脚本将无法工作:

dt = Current Data Table();
dt << New Column("Status", Character, Formula(
    If(:Name( "Grade" )==0, "fail",
       :Name( "Grade" )>100, "invalid",
       :Name( "Grade" )<0, "invalid")
));

Can you help me debug this script? 您能帮我调试此脚本吗?

I just tried the script and the formula is working for me. 我只是尝试了脚本,所以公式对我有用。

Here is some JSL which is a bit more complete which also adds the "Grade" column upon which "Status" depends. 这是一些更完整的JSL,它还添加了“状态”所依赖的“等级”列。

dt = Current Data Table();
dt << New Column( "Grade",
        Numeric,
        "Continuous",
        Format( "Best", 12 ),
    );
dt << New Column( "Status",
        Character,
        "Nominal",
        Formula(
            If(
                :Grade == 0, "fail",
                :Grade > 100, "invalid",
                :Grade < 0, "invalid"
            )
        )
    );

Perhaps the issue is that you don't already have a data table opened with a Grade column? 也许问题在于您尚未打开带有“成绩”列的数据表? Here's a script to create a brand new table with the formula and some values. 这是一个使用公式和一些值创建全新表的脚本。

New Table( "Grading Test",
    Add Rows( 7 ),
    New Column( "Grade",
        Numeric,
        "Continuous",
        Format( "Best", 12 ),
        Set Selected,
        Set Values( [45, 20, 100, 101, -4, 0, 120] )
    ),
    New Column( "Status",
        Character,
        "Nominal",
        Formula(
            If(
                :Grade == 0, "fail",
                :Grade > 100, "invalid",
                :Grade < 0, "invalid"
            )
        )
    )
);

I created that by interactively creating the table and using the red-triangle menu and selected "Copy Table Script". 我是通过交互式创建表并使用红色三角形菜单并选择“复制表脚本”来创建的。

I tried JMP 12.0, which version are you using? 我尝试了JMP 12.0,您使用的是哪个版本?

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

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