Ciao,
Sono nuovo nello scripting e apprezzerei molto qualsiasi aiuto con quanto segue:
Sto cercando di scrivere uno script che mi consenta di raggruppare e impilare colonne con suffissi di nomi variabili. La mia tabella è composta da poche colonne con nomi che non cambiano (cioè sorgente, frame) e molti altri (fino a centinaia) che iniziano con x, y, area, perimetro, AR e hanno il suffisso 1, 2, 3, ecc. così normalmente sembrerebbe questo ...
sorgente, frame, x1, y1, ar1, area 1, angle1, perimeter1, x2, y2, ar, area2, angle2, perimeter2, .... e così via ...
Apprezzerei molto qualsiasi aiuto nel mettere insieme uno script che raggrupperebbe tutti gli ex, tutti gli y, ecc., Indipendentemente dal numero. Dopo questo vorrei impilarli con una colonna che indica il suffisso e le altre colonne con i dati per x, y, area, perimetro.
Spero di essere stato chiaro.
Sto anche allegando un tavolino per renderlo più facile da seguire.
Grazie per qualsiasi aiuto,
Andres
Ecco uno script che penso farà quello che vuoi:
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"});