こんにちは、
私はスクリプトを書くのが初めてなので、以下の情報を提供していただければ幸いです。
変数名の接尾辞を使って列をグループ化してスタックできるようにするスクリプトを作成しようとしています。私のテーブルはx、y、area、perimeter、ARで始まり、接尾辞1、2、3などを持っていて変更されてはいけない名前(つまりsource、frame)と他の多く(最大何百も)の列から成ります。だから通常それはこのようになります...
source、frame、x 1、y 1、ar 1、area 1、angle 1、perimeter 1、x 2、y 2、ar、area 2、angle 2、perimeter 2、...など
数に関係なく、すべてのexes、すべてのysなどをグループ化するスクリプトをまとめることには、どんな助けも大いに感謝します。その後、接尾辞を示す1つの列と、x、y、面積、周囲のデータを含む他の列とを重ねて表示します。
うまくいけば、私は自分自身を明確にしました。
見やすくするために小さなテーブルも取り付けています。
助けてくれてありがとう、
アンドレス
これが私があなたが望むことをすると思うスクリプトです:
Names Default To Here( 1 );
dt = Current Data Table();
// Get all of the column names so we can get a count of the number of
// X and Y columns found
All Columns = dt << get column names;
// Loop through and find the number of Xnn columns & Ynn columns
XList = YList = {};
For( i = 1, i <= N Items( All Columns ), i++,
If( Uppercase( Substr( All Columns[i], 1, 1 ) ) == "X" & Is Missing( Num( Substr( All Columns[i], 2 ) ) ) == 0,
Insert Into( XList, Num( Substr( All Columns[i], 2 ) ) )
);
If( Uppercase( Substr( All Columns[i], 1, 1 ) ) == "Y" & Is Missing( Num( Substr( All Columns[i], 2 ) ) ) == 0,
Insert Into( YList, Num( Substr( All Columns[i], 2 ) ) )
);
);
start = min(XList);
end = max(XList);
// Error checking
If(end!=max(YList) | start!=min(YList) | N items(XList)!=N Items(YList),
dialog("errors in column matching found"); throw());
// Create Column Lists
For(i=1,i<=nItems(XList),i++,
XList[i]=column("X" || char(XList[i]));
YList[i]=column("Y" || char(YList[i]));
);
// Combine the lists
Stack Columns = XList || YList;
// Stack the data
dtStacked =dt << Stack(
columns( Stack Columns ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Eliminate missing rows( 1 ),
Drop All Other Columns( 1 ),
Number of Series( 2 ),
Contiguous
);
// Create the Suffix column
dtStacked << New Column("Suffix",character,formula(substr(:Label,2)));
// Remove the formula and leave the calculated value
dtStacked:Suffix << delete property("formula");
// Rename the columns, and delete unneeded columns
dtStacked:Data << Set Name("X");
dtStacked:Data 2 << Set Name("Y");
dtStacked << delete columns({"Label","Label 2"});