Hallo,
Ich bin neu in der Skripterstellung und würde mich sehr über jede Hilfe bei Folgendem freuen:
Ich versuche, ein Skript zu schreiben, mit dem ich Spalten mit Suffixen für Variablennamen gruppieren und stapeln kann. Meine Tabelle besteht aus ein paar Spalten mit Namen, die sich nicht ändern (dh Quelle, Rahmen) und vielen anderen (bis zu Hunderten), die mit x, y, Fläche, Umfang, AR beginnen und das Suffix 1, 2, 3 usw. haben. Also normalerweise würde es so aussehen ...
Quelle, Rahmen, x1, y1, ar1, Bereich 1, Winkel1, Umfang1, x2, y2, ar, Bereich2, Winkel2, Umfang2, ....und so weiter ...
Ich würde mich sehr über jede Hilfe beim Zusammenstellen eines Skripts freuen, das alle Exen, alle ys usw. unabhängig von der Anzahl gruppieren würde. Danach möchte ich sie mit einer Spalte stapeln, die das Suffix angibt, und die anderen Spalten mit den Daten für x, y, Fläche, Umfang.
Hoffentlich habe ich mich klar ausgedrückt.
Ich hänge auch eine kleine Tabelle an, um es einfacher zu machen, zu folgen.
Danke für jede Hilfe,
Andreas
Hier ist ein Skript, von dem ich denke, dass es das tut, was Sie wollen:
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"});