大家好,
需要帮助开发一个脚本来做多列的减法,列名和计数是可变的,
可以根据分析改变,
需要用来自同一行的所有值的差异填充列增量,
样本数据如下

你好@金瑟约瑟夫
你能举一个你想使用的公式的例子吗?这听起来像是我会在脚本工具加载项。

您好,感谢您的答复,
我正在使用 JMP15,你能帮忙指出我可以使用的代码吗,
我是 JMP 的初学者
提前致谢
你好 ,
我正在编写用于数据分析的脚本,并且需要在代码之间仅针对一个数据表实现此逻辑,
你能帮忙指出我可以使用的代码吗
提前致谢
这是我将使用的公式。它依赖于矩阵函数 Loc(),它返回矩阵中的所有非零条目。
x = :data[Row()] || :data1[Row()] ||
:data2[Row()] || :data3[Row()] ||
:data4[Row()] || :data5[Row()] ||
:data6[Row()] || :data7[Row()] ||
:data8[Row()] || :data9[Row()];
y = Loc( x );
Try( x[y[2]] - x[y[1]], . );
假设您不知道名称,也不知道列数,下面的代码将创建所需的公式,然后使用生成的公式创建新列
Names Default To Here( 1 );
dt = Current Data Table();
// Get the columns
colNames = dt << get column names( string, continuous );
// Build the formula
theExpr = "dt<<NEW column=""></NEW>

附上我使用的示例数据表
如果你需要多次使用它,你也可以把它变成一个函数。
这是一个例子:
- 功能
- 使用正则表达式筛选感兴趣的列
- 由于每个过滤器都需要 JMP16
- 使用 Loc() 和矩阵计算
- 使用值创建新的列增量
Names Default To Here(1);
//example datatable
dt = New Table("Untitled",
Add Rows(5),
Compress File When Saved(1),
New Column("Column 1",
Numeric,
"Continuous",
Format("Best", 12),
Set Values([1, 0, 0, 1, 0]),
Set Display Width(55)
),
New Column("Column 2", Numeric, "Continuous", Format("Best", 12), Set Values([0, 2, 3, 0, 0])),
New Column("Column 3",
Numeric,
"Continuous",
Format("Best", 12),
Set Values([0, 3, 0, 0, 0]),
Set Display Width(87)
),
New Column("Column 4", Numeric, "Continuous", Format("Best", 12), Set Values([3, 0, 4, 0, 0])),
New Column("col", Character, "Nominal", Set Values({"a", "a", "a", "a", "a"}))
);
difference_between_min_max = Function({dt_ref, col_prefix_regex},
{Default Local},
//get columnn names of interest based on col_prefix
col_names_all = dt_ref << Get Column Names("Numeric", "String");
col_names_of_interest = Filter Each({val}, col_names_all,
!IsMissing(Regex(val, col_prefix_regex));
);
show(col_names_of_interest);
//all values for columns of interest, transpose for calculations
m = Transpose(dt_ref[0, col_names_of_interest]);
//replace 0 with missing to avoid calculation with those
m[Loc(m, 0)] = .;
//Get max and min values and deduct them
result = V Max(m) - V Min(m);
//Replace missing values with 0 for final results
result[Loc(result,.)] = 0;
//we could return result matrix here OR we can create new column with the function
dt_ref << New Column("delta", Numeric, Continuos, Set Values(result));
);
//example table in this example
difference_between_min_max(dt, "(Column )");
//example table by txnelson
//difference_between_min_max(Current Data Table(), "^(\D{1})$");
也可以变成自定义功能
现在我明白了,在那种情况下,我会亲自在脚本工具加入。我会选择所有要转换的列(我认为是 data1-data10),然后从 Cols 菜单(安装加载项后可用)中选择 Custom Transformation 并输入以下设置:
