Assegnazione automatica delle colonne ai gruppiHo faticato a capirlo. Ho una tabella (Tabella1) che ha colonne che voglio raggruppare. La Tabella2 ha i nomi delle colonne e le etichette di gruppo che voglio usare. Voglio creare uno script e automatizzare la creazione della tabella raggruppata, come mostrato nello screenshot qui sotto. Qualsiasi suggerimento su come farlo sarebbe apprezzato.

ecco gli script per creare la Tabella1 e la Tabella2 mostrate sopra
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"} ) )
);
Automazione e scriptingRe: Automazione nell'assegnazione delle colonne ai gruppiUso quasi la stessa idea di Jim, ma mi piace separare la raccolta e la creazione del gruppo nei loro cicli
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);
);Re: Automazione nell'assegnazione delle colonne ai gruppiEcco un modo per gestire il problema:
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 );
)
;