Automatisches Zuordnen von Spalten zu GruppenIch habe Probleme, das herauszufinden. Ich habe eine Tabelle (Tabelle1) mit Spalten, die ich gruppieren möchte. Tabelle2 hat die Spaltennamen und Gruppenbezeichnungen, die ich verwenden möchte. Ich möchte die Erstellung der gruppierten Tabelle skripten und automatisieren, wie im Screenshot unten gezeigt. Ich bin für alle Vorschläge dankbar, wie das geht.

Hier sind Skripte zum Erstellen der oben gezeigten Tabellen 1 und 2
dt1 = New Table( "Table1",
Add Rows( 3 ),
New Column( "A", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [35, 10, 88] ) ),
New Column( "B", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 3, 2] ) ),
New Column( "C", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 3, 1] ) ),
New Column( "D", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 2, 2] ) )
);
dt2 = New Table( "Table2",
Add Rows( 4 ),
New Column( "Name", Character, "Nominal", Set Values( {"A", "B", "C", "D"} ) ),
New Column( "GroupName", Character, "Nominal", Set Values( {"G1", "G1", "G2", "G2"} ) )
);
Automatisierung und SkriptingBetreff: Automatisches Zuordnen von Spalten zu GruppenIch verwende fast die gleiche Idee wie Jim, aber ich mag es, die Gruppensammlung und -erstellung in eigene Schleifen aufzuteilen
Names Default To Here(1);
dt1 = New Table("Table1",
Add Rows(3),
New Column("A", Numeric, "Continuous", Format("Best", 12), Set Values([35, 10, 88])),
New Column("B", Numeric, "Continuous", Format("Best", 12), Set Values([2, 3, 2])),
New Column("C", Numeric, "Continuous", Format("Best", 12), Set Values([1, 3, 1])),
New Column("D", Numeric, "Continuous", Format("Best", 12), Set Values([2, 2, 2]))
);
dt2 = New Table("Table2",
Add Rows(4),
New Column("Name", Character, "Nominal", Set Values({"A", "B", "C", "D"})),
New Column("GroupName", Character, "Nominal", Set Values({"G1", "G1", "G2", "G2"}))
);
aa_groups = Associative Array(Column(dt2, "GroupName"));
For Each({key}, aa_groups << get keys,
aa_groups[key] = dt2 << Get Rows Where(:GroupName == key);
);
For Each({{name, cols}}, aa_groups,
dt1 << Group Columns(name, cols);
);Betreff: Automatisches Zuordnen von Spalten zu GruppenSo können Sie das Problem beheben:
Names Default To Here( 1 );
dt1 = New Table( "Table1",
Add Rows( 3 ),
New Column( "A", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [35, 10, 88] ) ),
New Column( "B", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 3, 2] ) ),
New Column( "C", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 3, 1] ) ),
New Column( "D", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 2, 2] ) )
);
dt2 = New Table( "Table2",
Add Rows( 4 ),
New Column( "Name", Character, "Nominal", Set Values( {"A", "B", "C", "D"} ) ),
New Column( "GroupName", Character, "Nominal", Set Values( {"G1", "G1", "G2", "G2"} ) )
);
GroupNames = Associative Array( dt2:GroupName ) << get keys;
For Each( {theGroup}, GroupNames,
// Create a list for a group
theRows = dt2 << get rows where( :GroupName == theGroup );
grpList = {};
For Each( {rowValue}, theRows, Insert Into( grpList, dt2:Name[rowValue] ) );
dt1 << Group Columns( theGroup, grpList );
)
;