Running average by data series using For Loop and same script on multiple columns<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />Hello,
I am running a three-point moving average [MA] in data series of fixed length, and collected at fixed time intervals [i.e., series of 150 data points collected every 30 minutes for weeks at the time]. A traditional MA would merge two data series together, so I ended up adding a new column with data series [incrementing numbers using "Sequence( , , ,)"], and using it as a limiter for the range where the MA should run. The script works and it is quite simple, but I want to use a more effective one.
Is there a way to do this using a For Loop where "i" is the data series ID?
How do I run the same script on multiple columns without having to change the variable name?
This is the script I am currently using:

| If( :Time > 1 & :Time < 149, |
Mean(
:T1_F[Row() - 1, Empty()],
:T1_F[Row(), Empty()],
:T1_F[Row() + 1, Empty()],),
.)
Where "T1_F" is my Y variable to smooth, and I have a couple of hundred Y's to smooth.
Any advise would be appreciated.
-JGL
Re: Running average by data series using For Loop and same script on multiple columnsHi JGL,
One solution is to build a loop using Eval(Parse(Eval Insert())) to insert your desired columns into a formula. An example script is below.
// Example.
Names Default To Here( 1 );
bigClass = Open( "$SAMPLE_DATA/Big Class.jmp" );
colList = List( :height, :weight ); // Columns to create moving averages.
For( i = 1, i <= Length( colList ), i++,
col = Column( colList[i] );
colName = Concat( "MA(", colList[i] << Get Name(), ")" );
Eval(
Parse(
Eval Insert(
"bigClass << New Column( \!"^colName^\!",
Numeric,
Continuous,
Format( \!"Best\!", 12 ),
Formula( Mean( As Column( ^col^ )[Row() -1, Empty()],
As Column( ^col^ )[Row(), Empty()],
As Column( ^col^ )[Row() + 1, Empty()] ) ) );"
)
)
);
);