对子集列执行公式我创建了一个脚本来创建较大表的子集表,但它无法正常工作。 我的目标是让用户在子集表中选择他们想要的列,然后让脚本在将数据放入新表之前对列执行公式。到目前为止,我的脚本将拉出用于用户交互的对话框,但是当我选择对话框中的列时,它们并不是显示在子集表中的列。 我不确定我的问题出在哪里。 (注意:用户将选择其中包含数据的列,而不是示例信息,因此在示例中,列名称以“Column 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”,这样就可以修复它
回复:对子集列执行公式您为第二个表发送的第二个代码似乎不起作用。 我花了几个小时尝试不同的事情。 我注意到缺少两个 (。 这有助于代码正常运行,但是删除“<”符号的代码部分似乎无法正常运行。 如果我删除那段代码,表格最终会检测到的值为 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;
)
)
);回复:对子集列执行公式这对于“检测”表非常有用,因此对于我的第二个表,我想将变为零的值切换到零,因此我认为这种方法行不通。 我想保留带有 < 符号的单元格,并将其余单元格设置为零。 然后我想删除 < 符号,只留下数值。 在我的脑海中,我想我会按照你的方式进行循环,然后添加 if/else 语句?
感谢您发布 if/else 语句。 我的问题是在 else 的列名之前没有 num() !
回复:对子集列执行公式这是脚本中的一个更改,我认为您可能会发现这是一个很好的方法。我将您想要做的解释为创建一个数字列,其中包含您选择的字符列中的值,但如果这些值包含“<”符号,请将这些条目设置为零 (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;
)
)
);