如何創建將多列作為輸入的自定義轉換函數?腳本指南在描述如何製作新的自定義轉換函數方面非常有用,但對於如何處理多列並不是很清楚。
如何創建將多列作為輸入的自定義轉換函數? 例如,如果我選擇一個 X、一個 Y 和一個 Z 列並且想要獲取這三列的 RSS(平方根)?
另外,如果順序很重要,那麼該順序是如何設置的? 是選擇列的順序嗎?
回复:如何創建一個將多列作為輸入的自定義轉換函數?funcDef = Function( { number }, { i, sum },
If( Is List( number ),
Sqrt( Summation( i = 1, N Items( number ), number[i]^2 ) ),
.
);
);
description = "This function returns the root sum squared of a list numbers.";
parmHint = "a list of numbers";
/* create function using variables
the commands can also be accepted as arguments in New Custom Function */
newAdd = New Custom Function( "mySpace", "RSS", funcDef );
newAdd << Description( description );
newAdd << Prototype( "mySpace:RSS( {} )" );
newAdd << Example( "mySpace:RSS( {1,2,3} )" );
// expr() Examples need to be passed inside NameExpr()
newAdd << Parameter( "List", parmHint );
newAdd << Formula Category( "MyNumberStuff" );
// add mySpace:RSS function to system
Add Custom Functions( newAdd );回复:如何創建一個將多列作為輸入的自定義轉換函數?對不起,我太慢了,我不知道該怎麼做。回复:如何創建一個將多列作為輸入的自定義轉換函數?好的,然後將 Here 命名空間替換為您自己的命名空間。
回复:如何創建一個將多列作為輸入的自定義轉換函數?我將該函數複製/粘貼到一個新的 JSL 腳本中並運行它,但日誌顯示此錯誤:“無法重新定義預定義的 JMP 命名空間”回复:如何創建一個將多列作為輸入的自定義轉換函數?這是一個新函數,它接受一個列表並返回相同的計算。
Names Default to Here( 1 );
// example
my numbers = List( 1, 2, 3, 4, 5 );
// define it
funcDef = Function( { number }, { i, sum },
If( Is List( number ),
Sqrt( Summation( i = 1, N Items( number ), number[i]^2 ) ),
.
);
);
// test it
Show( funcDef( my numbers ) );回复:如何創建一個將多列作為輸入的自定義轉換函數?我會查找列表參數,謝謝。
不知道您在雙引號中在說什麼,或者關於 JMP 提供自定義函數和轉換的評論的基礎。回复:如何創建一個將多列作為輸入的自定義轉換函數?我避免使用雙引號。 它們通常沒有持久的價值。 JMP 提供自定義函數和自定義轉換。 為什麼不按預期使用它們?
如果您的函數必須使用可變數量的參數,您總是可以使用列表參數而不是標量參數。
回复:如何創建一個將多列作為輸入的自定義轉換函數?感謝您的回复,馬克! 幾個快速的後續問題:
1. 我知道 JMP *supports* 多列轉換函數——只是它還不支持多列 *custom* 轉換嗎?
2. 你的函數接受 3 個參數——是否可以定義一個接受任意數量參數的函數?回复:如何創建一個將多列作為輸入的自定義轉換函數?我認為自定義功能是您的情況的更好選擇。 自定義轉換僅限於單個輸入。 自定義函數不受此限制。
funcDef = Function( {x, y, z}, Sqrt( Sum( x^2, y^2, z^2 ) ) );
description = "This function returns the root sum squared of three numbers.";
// examples can be multiple statements inside expr()
ex2 = Expr(
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Here:RSS( :age[1], :age[2], :age[3] );
);
parmHint1 = "x value";
parmHint2 = "y value";
parmHint3 = "z value";
/* create function using variables
the commands can also be accepted as arguments in New Custom Function */
newAdd = New Custom Function( "Here", "RSS", funcDef );
newAdd << Description( description );
newAdd << Prototype( "Here:RSS(x,y,z)" );
newAdd << Example( "Here:RSS(1,2,3)" );
// expr() Examples need to be passed inside NameExpr()
newAdd << Example( Name Expr( ex2 ) );
newAdd << Parameter( "Number", parmHint1 );
newAdd << Parameter( "Number", parmHint2 );
newAdd << Parameter( "Number", parmHint3 );
newAdd << Formula Category( "NumberStuff" );
// add myNamespace:Add Ten function to system
Add Custom Functions( newAdd );
函數內的表達式可能包含滿足任何正確順序需求的邏輯。