Dynamic Column Reference in FunctionHello,
I'm trying to write a function that refers to a certain row of a column and trying to make it dynamic where I can run it on any column name. Using the Big Class table as sample, I'm trying to run the calculation on the height column but I couldn't get it working unless its hardcoded in the function. Also the lag function doesn't seem to work within a function.
This is the script that I have.
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Row() = 4;
ii = 4;
Test = Function({tag},
Y = tag[ii] - tag[ii-1]; // this doesn't work
//Y = height[ii] - height[ii-1]; this works
X = lag(tag,1); // this doesn't work
//X = lag(height,1); this works
);
Test(height)
Thanks in advance
Re: Dynamic Column Reference in FunctionThis is great now I got it.
Thanks very much! Really appreciate it.Re: Dynamic Column Reference in FunctionSee the annotated script below
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")