これは、データテーブルに変数の複数のラグ列を作成するために使用できるスクリプトです。 これは、データが時間内に歪んでいる場合に役立ちます。 たとえば、センサーデータが時間内にキャプチャされ、テーブル内のデータが時系列に並べられている場合、1つのバッチまたは製品に対応するデータが複数の行に分散する場合があります。 このスクリプトを使用すると、分析用にデータを簡単に調整できます。
Names Default To Here(1);
dt=current data table();
/* Query the user for a column roles. */
cdlg = Column Dialog(
ycol = ColList( "Y", MinCol( 1 ), MaxCol( ), Data Type("Numeric"),Modeling Type("Continuous") ),
Line Up( 2,
"Start Lag", slag = Edit Number( 32 )),
Line Up( 2,
"End Lag", elag = Edit Number( 38 ))
);
If( cdlg["Button"] == -1, Throw( "User cancelled" ) );
Remove From( cdlg ); Eval List( cdlg );
range=elag-slag;
If( range <= 0, Throw( "Bad Range" ) );
/* Unload the values from the Column Dialog */
my_collist = cdlg["ycol"];
/*Number of columns chosen*/
numcols=N Items(my_collist);
for(i=1,i<=numcols,i++,
for(j=slag,j<=elag,j++,
newcol=dt << New Column( Char(my_collist[i]) ||" Lag "||Char(j));
newVals = (J(j,1,.) |/ (Column(dt,my_collist[i]) << Get Values))[1::N Row(dt)];
newcol<<SET values=""></SET>