大家好,
需要幫助開發一個腳本來做多列的減法,列名和計數是可變的,
可以根據分析改變,
需要用來自同一行的所有值的差異填充列增量,
樣本數據如下

你好@金瑟約瑟夫
你能舉一個你想使用的公式的例子嗎?這聽起來像是我會在腳本工具加載項。

您好,感謝您的答复,
我正在使用 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 並輸入以下設置:
