使用 veribles 建立/新增列嘿夥計們,我為這個令人困惑的標題道歉。我不知道如何表達它。
我的問題是:我有一個代碼,其中使用長條件添加新列。
除一個參數變化外,所有列的條件均相同。
有沒有辦法,而不是每次編寫完整的程式碼和帶有新參數值的條件,創建一個模板(如函數),我將使用變數而不是每次需要的值時發送到的參數對於新專欄的條件?
自動化和腳本編寫基礎資料分析與建模回覆:使用 veribles 建立/新增列您可以使用函數或表達式來實現類似的目的
https://www.jmp.com/support/help/en/18.0/#page/jmp/advanced-expressions-macros-and-lists.shtml#ww339382
https://www.jmp.com/support/help/en/18.0/#page/jmp/advanced-functions.shtml#
使用 Eval Insert、Eval Expr、Parse 和 Substitute 將一個表達式插入另一個表達式
回覆:使用 veribles 建立/新增列無需編寫任何程式碼。
從 JMP 18 開始,這非常簡單 - 只需查看討論/公式/ - 功能#3。
簡而言之:
選擇要用作輸入的列,然後右鍵單擊列標題並單擊
新公式欄/ 
最後一步,輸入公式並點擊
[我選擇了 128 列,因此建立 128 。
如果您選擇了 N 列,它將建立 N 列:)
回覆:使用 veribles 建立/新增列如果您想透過新公式右鍵選單一次又一次地使用完全相同的公式,您可以建立自己的「自訂函數」並啟用「轉換類別」選項以使其顯示在選單中。
重新啟動後,必須再次執行程式碼,因此請將其包含在加載項或啟動腳本中。
Names Default To Here( 1 );
myAdd =
New Custom Function(
"custom",
"Add",
Function( {x, y = 1},
x + y - 1
)
);
myAdd << Transform Category( 1 );來自腳本索引:

但這種做法非常「靜態」。要獲得更改參數的可能性,您必須在這裡投票:
新的公式列選單:使用者定義的迷你 GUI
回覆:使用 veribles 建立/新增列下面是一個添加數字的函數範例。它缺少一些檢查來成為“好”函數,但確實提供了必要的想法,即必須評估可能更改的值(在本例中要添加的列名稱和編號)(請參閱將一個表達式插入另一個表達式...我之前有提到)
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
cols = {"height", "weight"};
add_num_to_col = Function({dt, colname, num_to_add}, {Default Local},
new_col = Eval(EvalExpr(
dt << New Column(colname || " add " || char(num_to_add), Numeric, Continuous, Formula(
Expr(NameExpr(AsColumn(dt, colname))) + Expr(num_to_add)
));
));
return(new_col);
);
col1 = add_num_to_col(dt, "height", 10);
col2 = add_num_to_col(dt, "height", 20);
col3 = add_num_to_col(dt, "weight", 5);
Write();
有時使用 Eval(Substitute()) 更乾淨、更容易理解解決方案,它可能看起來像這樣
add_num_to_col = Function({dt, colname, num_to_add}, {Default Local},
new_col = Eval(Substitute(
Expr(dt << New Column(colname || " add " || char(num_to_add), Numeric, Continuous, Formula(
_colname_ + _num_to_add_
))),
Expr(_colname_), Name Expr(AsColumn(dt, colname)),
Expr(_num_to_add_), num_to_add
));
return(new_col);
);回覆:使用 veribles 建立/新增列前面的方法的組合 - 有一點改變:
- 建立自訂函數 *)
- 將其新增至公式類別
- 右鍵單擊列標題,然後按一下新公式列/

- 使用新公式
- ....並手動輸入參數:

*)
Add Custom Functions(
New Custom Function(
"custom",
"add++",
Function( {column, num_to_add},
{Default Local},
column,
num_to_add
),
<<FORMULA category=""></FORMULA>The benefit: the user can enter specific parameters for every new column.
The disadvantage: no <STRONG><EM>批次</EM> </STRONG>mode like in the previous posts.<BR /><BR />kind of disadvantage: JMP doesn't <EM>解決/替換</EM> the formula, it keeps it as <FONT face="courier new,courier">新增++(...)</FONT>.<BR /> To keep it alive the formula definition has to be executed again after a restart of JMP - and maybe: shared with colleagues.
回覆:使用 veribles 建立/新增列謝謝大家的幫忙。
我有一個新的相關問題,也許有人可以向我解釋。
我使用以下方法刪除特定列中沒有資料的行:
dt << select where( 缺失( Column( dt,col_name )[row()] ));
*因此,它確實刪除了正確的行,但同時刪除了列中的值。有人能指出我的錯誤嗎?
在此附上腳本本身:
回覆:使用 veribles 建立/新增列Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
col_name="x";
New column(col_name); // maybe another column with the same name?
new_col = New column(col_name, Formula(if(:height>60,1 )));
// get the correct column name - uncomment to make it work
//col_name = new_col << get name();
dt << select where( Is missing( Column( dt,col_name )[row()] ));
wait(1);
dt << delete rows;
回覆:使用 veribles 建立/新增列我不建議使用字串來引用列。這種情況經常發生,實際的列是透過新增「2」來建立的 - 並且該字串將指向另一列。
產生列時,您將獲得該列的句柄。只需使用這個手柄 - 它就會引導您到正確的列:
Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
col_name="x";
new_col = New column(col_name, Formula(if(:height>60,1 )));
dt << select where( Is missing( new_Col[] ));
回覆:使用 veribles 建立/新增列我也不喜歡[]將列Column(col_name)替換為當前值As column(col_name) 。
:col 兩者都可以 - 我從@jthi那裡學到了:
Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
col_name="x";
new_col = New column(col_name, Formula(if(:height>60,1 )));
myCol = Name Expr(As Column(new_col)); // very cool trick (c) Jarmo
Show(Name Expr(myCol));
dt << select where( Is missing( myCol ));