函数中的动态列引用你好,
我正在尝试编写一个引用列的某一行的函数,并尝试使其动态化,以便我可以在任何列名称上运行它。 使用 Big Class 表作为示例,我尝试在高度列上运行计算,但除非在函数中硬编码,否则我无法使其工作。 此外,滞后函数似乎不适用于函数内。
这是我的脚本。
dt =打开( “$SAMPLE_DATA/大类.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")