嗨,
我是脚本的新手,非常感谢以下任何帮助:
我正在尝试编写一个脚本,允许我对具有可变名称后缀的列进行分组和堆叠。我的表包含几个名称不变的列(即源,框架)和许多其他(最多数百个)以x,y,区域,周长,AR开头并具有后缀1,2,3等的列。通常看起来像这样......
源,框架,x1,y1,ar1,区域1,角度1,周长1,x2,y2,ar,area2,angle2,perimeter2,....等等......
我非常感谢任何帮助,整理一个脚本,将所有的exes,所有的y等组合在一起,无论数字如何。在此之后,我想用一列指示后缀,其他列与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"});