函數中的動態列引用你好,
我正在嘗試編寫一個引用列的某一行的函數,並嘗試使其動態化,以便我可以在任何列名稱上運行它。 使用 Big Class 表作為範例,我嘗試在高度列上運行計算,但除非在函數中對其進行硬編碼,否則我無法使其工作。 此外,滯後函數似乎不適用於函數內。
這是我的腳本。
dt =打開( “$SAMPLE_DATA/Big Class.jmp” );
行()= 4;
ii = 4 ;
測試=功能({標籤},
Y = 標籤[ii] - 標籤[ii- 1 ]; // 這不起作用
//Y = 高度[ii] - 高度[ii-1];這有效
X =落後(標籤, 1 ); // 這不起作用
//X = 滯後(高度,1);這有效
);
測試(身高)
先致謝
回覆:函數中的動態列引用這太棒了,我現在明白了。
非常感謝! 真的很感激。回覆:函數中的動態列引用請參閱下面帶有註釋的腳本
t = Open( "$SAMPLE_DATA/Big Class.jmp" );
Row() = 4;
ii = 4;
Test = Function({tag},
Y = column(t,tag)[ii] - column(t,tag)[ii-1]; // this doesn't work
//Y = height[ii] - height[ii-1]; this works
X = lag(column(t,tag)[ii],1); // this doesn't work
//X = lag(height,1); this works
// If you want the calculated values to be returned to a value such as calling the function
// rr = Test("Height")
// uncomment the code below
//YXList = {};
//insert into(YXList,Y);
//insert into(YXList,X);
//return(YXList);
);
// If you specify
// Test(height);
// JMP will look for the value of a variable called height
// You need to pass the column name as a string and have the
// function process it
Test("height")