在子集列上执行公式我创建了一个脚本来制作更大表的子集表,但它无法正常工作。我的目标是让用户在子集表中选择他们想要的列,然后让脚本在将数据放入新表之前对列执行公式。 到目前为止,我的脚本将拉出用于用户交互的对话框,但是当我选择对话框中的列时,它们不是显示在子集表中的那些。我不确定我的问题出在哪里。(注意:用户将选择包含数据的列,而不是样本信息,因此在示例中,列名称以“列 10...”开头。)
此外,我不确定在哪里插入公式。基本上,用户从对话框中选择的列将有一些带有 < 符号的单元格,对于新的子集表,我希望任何没有小于符号的单元格变为零,而任何带有 < 符号的单元格都带有 < 符号删除仅将其旁边的数字放置在子集表中。因此,新的子集表具有检测值的零和未检测化合物的检测限。
到目前为止,这是我的脚本。
Names Default To Here( 1 );
dt = Data Table("Example Data");
col_dlg = new window("Column Select",
panelbox("Select columns to create NonDetect table with",
col_clist = collistbox(all, width(200)),
buttonbox("Ok",
selected_column_list = col_clist << getselected;
dt2 = dt << Subset(Output Table("NonDetect"),columns(col_clist));
col_dlg << close window;
)
)
);感谢您的任何帮助!
回复:在子集列上执行公式现在,您有机会向讨论社区的贡献者付款........深入了解脚本指南和脚本索引,成为有经验的用户并通过您的参与来回馈。
回复:在子集列上执行公式那行得通!非常感谢您的时间和耐心。我真的很感激!
莱西
回复:在子集列上执行公式事实证明 Substr() 函数在选定的行中不起作用(不知道为什么),所以我稍微修改了代码并测试了它(我显然没有测试我的上一个版本)
Names Default To Here( 1 );
dt = Data Table( "Example Data" );
col_dlg = New Window( "Column Select",
Panel Box( "Select columns to create NonDetect table with",
col_clist = Col List Box( all, width( 200 ) ),
Button Box( "Ok",
selected_column_list = col_clist << getselected;
dt2 = dt << Subset( Output Table( "NonDetect" ), columns( selected_column_list ) );
// Loop across the columns in the new data table and convert them to numeric
// Cells with nonnumeric values will be set to Missing Values, which then can
// be identified and set to 0
For( i = 1, i <= N Items( selected_column_list ), i++,
// Select all of the currently non selected columns and unselect the current ones
dt2 << select where( Contains( As Column( dt2, selected_column_list[i] ), "<" ) == 0 );
// Set for the target column all of the currently selected rows to "0"
Column( dt2, selected_column_list[i] )[dt2 << get selected rows] = "0";
// Find the rows with the "<" in them
dt2 << invert row selection;
selRows = dt2 << get selected rows;
//selRows= dt2 << Get Rows Where(Contains(As Column( dt2, selected_column_list[i] ),"<" )==1);
// Get rid of the "<" making the value a valid numeric value
For( k = 1, k <= N Rows( selRows ), k++,
Column( dt2, selected_column_list[i] )[selRows[k]] = Substr( As Column( dt2, selected_column_list[i] )[selRows[k]], 2 )
);
// Convert the column to a numeric/continuous column
Column( dt2, selected_column_list[i] ) << data type( numeric ) << modeling type( continuous );
);
col_dlg << close window;
)
)
);回复:在子集列上执行公式也许我把 ( 放在了错误的位置?这就是我现在所拥有的。
Names Default To Here( 1 );
dt = Data Table( "Example Data" );
col_dlg = New Window( "Column Select",
Panel Box( "Select columns to create NonDetect table with",
col_clist = Col List Box( all, width( 200 ) ),
Button Box( "Ok",
selected_column_list = col_clist << getselected;
dt2 = dt << Subset( Output Table( "NonDetect" ), columns( selected_column_list ) );
// Loop across the columns in the new data table and convert them to numeric
// Cells with nonnumeric values will be set to Missing Values, which then can
// be identified and set to 0
For( i = 1, i <= N Items( selected_column_list ), i++,
// Select the rows where there is a "<" for the target column
dt2 << Select where(Contains(As Column( dt2, selected_column_list[i] ),"<" )==1);
// Get rid of the "<" making the value a valid numeric value
Column( dt2, selected_column_list[i] )[dt2 << get selected rows ()] =
substr(As Column( dt2, selected_column_list[i] ),2);
// Select all of the currently non selected columns and unselect the current ones
dt2 << invert row selection;
// Set for the target column all of the currently selected rows to "0"
Column( dt2, selected_column_list[i] )[dt2 << get selected rows ()] = "0";
// Convert the column to a numeric/continuous column
Column( dt2, selected_column_list[i] ) << data type( numeric ) <<
modeling type( continuous );
);
col_dlg << close window;
)
)
);回复:在子集列上执行公式谢谢你快速的回复!我尝试了 2 但我最终从检测到的值中得到了零,并且对于带有 < 符号的任何单元格都得到了空白。我得到的结果与 1 相同。
回复:在子集列上执行公式哎呀.....我的错误,将 substr() 函数中的“1”更改为“2”,这应该可以解决它
回复:在子集列上执行公式您为第二个表发送的第二个代码似乎不起作用。我花了几个小时尝试不同的东西。我注意到两个 ('s 丢失了。这有助于代码正常运行,但是删除“<”符号的代码部分似乎无法正常运行。如果我删除那段代码,表格会以检测到的值为 0 结束,而 ND 值仍然完好无损,带有 < 符号。我试过摆弄它,但还没有弄清楚。有什么线索吗?:)
谢谢!
回复:在子集列上执行公式这是处理您的第二种情况的代码
Names Default To Here( 1 );
dt = Data Table( "Example Data" );
col_dlg = New Window( "Column Select",
Panel Box( "Select columns to create NonDetect table with",
col_clist = Col List Box( all, width( 200 ) ),
Button Box( "Ok",
selected_column_list = col_clist << getselected;
dt2 = dt << Subset( Output Table( "NonDetect" ), columns( selected_column_list ) );
// Loop across the columns in the new data table and convert them to numeric
// Cells with nonnumeric values will be set to Missing Values, which then can
// be identified and set to 0
For( i = 1, i <= N Items( selected_column_list ), i++,
// Select the rows where there is a "<" for the target column
dt2 << Select where(Contains(As Column( dt2, selected_column_list[i] ),"<" )==1);
// Get rid of the "<" making the value a valid numeric value
Column( dt2, selected_column_list[i] )[dt2 << get selected rows )] =
substr(As Column( dt2, selected_column_list[i] ),1);
// Select all of the currently non selected columns and unselect the current ones
dt2 << invert row selection;
// Set for the target column all of the currently selected rows to "0"
Column( dt2, selected_column_list[i] )[dt2 << get selected rows )] = "0";
// Convert the column to a numeric/continuous column
Column( dt2, selected_column_list[i] ) << data type( numeric ) <<
modeling type( continuous );
);
col_dlg << close window;
)
)
);回复:在子集列上执行公式这对 Detect 表很有用,所以对于我的第二个表,我想切换变为零的值,所以我认为这种方法行不通。我想保留具有 < 符号的单元格并将其余单元格转为零。然后我想删除 < 符号,只留下数值。在我的脑海中,我想我会像你一样做循环,然后添加一个 if/else 语句?
并感谢您发布 if/else 语句。我的问题是在我的列名之前没有 num() 为 else!
回复:在子集列上执行公式这是脚本中的一个更改,我认为您可能会发现这是一个很好的方法。 我解释为您想要做的是创建一个数字列,其中包含您选择的字符列中的值,但如果这些值包含“<”符号,则将这些条目设为零(0)。 下面的脚本执行此操作,而无需创建新列。 它将列转换为数字,并将“<”单元格设置为零。
Names Default To Here( 1 );
dt = Data Table( "Example Data" );
col_dlg = New Window( "Column Select",
Panel Box( "Select columns to create NonDetect table with",
col_clist = Col List Box( all, width( 200 ) ),
Button Box( "Ok",
selected_column_list = col_clist << getselected;
dt2 = dt << Subset( Output Table( "NonDetect" ), columns( selected_column_list ) );
// Loop across the columns in the new data table and convert them to numeric
// Cells with nonnumeric values will be set to Missing Values, which then can
// be identified and set to 0
For( i = 1, i <= N Items( selected_column_list ), i++,
// Change the column to numeric/continuous
// The names in the data table are very complex, containing symbols, etc.
// that JMP will confuse as operators. Therefore, using the Column()
// function, or a :Name(" ") function to wrap around the column name
// needs to be used
Column( dt2, selected_column_list[i] ) << data type( numeric ) <<
modeling type( continuous );
// Now find all of the rows in the table that have Missing Values
// in the target column, and then set them all to "0" in one
// statement
Column( dt2, selected_column_list[i] )[dt << get rows where(
Is Missing( As Column( dt2, selected_column_list[i] ) )
)] = 0;
);
col_dlg << close window;
)
)
);
您可以创建新列并设置您在上次回复中指出的公式。 您所提供的问题是处理复杂的列名。这是如何工作的
If( Contains( :Name( "Column 10 1,2,3,4,6,7,8-HpCDD" ), "<" ),
0,
Num( :Name( "Column 10 1,2,3,4,6,7,8-HpCDD" ) )
)
回复:在子集列上执行公式我认为这就是我遇到麻烦的地方,我非常精通 excel,并且已经在其中进行了 9 年的所有数据分析。我只是想转移一下,我很难在 jmp 中使用 if/then 语句(除其他外)。我会用excel写出来,也许你能帮忙?
我将制作其中两个子集表。一种用于检测值,一种用于未检测值。对于检测到的值,我会执行 if/then 语句,例如 =if(isnumber(J2),J2,0)。对于未检测到的值,我会执行类似 =if(isnumber(J2),0,J2) 的操作。
我试图在 JMP 中将其切换为
如果(包含(:第 10 列 1,2,3,4,6,7,8-HpCDD , “<” ), 0 ,:第 10 列 1,2,3,4,6,7,8-HpCDD )
但即使我自己创建一列并插入公式,它似乎也不起作用。
所以基本上,在我的脚本中,我将包括两个部分,一个用于 NonDetect 表,一个用于 Detect 表,我希望使用 if then 语句对列进行转换?最后,我会将两个数据表发送到 R 以使用 NonDetect 子集中剩余的 DL 来估算非检测值。我希望这能解释它吗?
回复:在子集列上执行公式你要计算的公式是什么?它真的需要创建一个新列吗?请记住,这不是 Excel。 要生成值或结果,不必将它们放入列中……还有其他结构。 你能更详细地描述你想要做什么吗?
回复:在子集列上执行公式啊,那行得通。
有没有办法在将数据放入新表之前完成数据的公式?如果没有,我的想法是在子集表中创建新列,在新列中完成计算,然后删除原始列(使用脚本)。有没有更有效的方法来做到这一点?
谢谢!
回复:在子集列上执行公式您引用的是显示对象 col_clist,而不是您已放入 Selected_column_list 的内容。
Names Default To Here( 1 );
dt = Data Table( "Example Data" );
col_dlg = New Window( "Column Select",
Panel Box( "Select columns to create NonDetect table with",
col_clist = Col List Box( all, width( 200 ) ),
Button Box( "Ok",
selected_column_list = col_clist << getselected;
dt2 = dt << Subset( Output Table( "NonDetect" ), columns( selected_column_list ) );
col_dlg << close window;
)
)
);