Sto scrivendo una funzione di supporto che rinomina un gruppo di colonne se contiene un nome di colonna specifico.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
/*//Use if already existing
dt = Data Table ("Cities");
*/
dt << group columns( "xy", {:X, :y} );
dt << group columns( "pollutants", :Ozone :: :Lead );
match_col = "X";
new_name = "coordinates";
groups_list = dt << get column groups names;
show(groups_list);
For Each({grp, ig}, groups_list,
cols = dt << get column group( grp );
show(cols);
For Each ({column, ic}, cols,
show(column);
colname = column << Get Name;
If(colname == match_col,
try(dt << rename column group( grp, new_name );)
)
);
);
Questo funziona bene con colonne raggruppate di base, ma non funziona se è presente un gruppo ereditato da un riferimento di collegamento:
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
dt_state = Open( "$SAMPLE_DATA/State Abbreviations.jmp" );
//Need more than 1 column
dt_state << New Column( "Dummy", Numeric, "Continuous", Format( "Best", 12 ));
//Link Tables
dt_state:Abbreviations << Set Property( "Link ID", 1 );
dt:State << Set Property("Link Reference", Reference Table(dt_state));
/*//Use if already existing
dt = Data Table ("Cities");
dt_state = Data Table( "State Abbreviations" );
*/
dt << group columns( "xy", {:X, :y} );
dt << group columns( "pollutants", :Ozone :: :Lead );
match_col = "X";
new_name = "coordinates";
groups_list = dt << get column groups names;
show(groups_list);
For Each({grp, ig}, groups_list,
cols = dt << get column group( grp );
show(cols);
For Each ({column, ic}, cols,
show(column);
colname = column << Get Name;
If(colname == match_col,
try(dt << rename column group( grp, new_name );)
)
);
);
Firstly, the << Get Name function errors on :Ozone, which worked fine in the simpler example.
Anche se l'errore viene risolto, la colonna collegata appare diversa nel registro:
column = :Y;
column = Referenced Column(<STRONG>"Stati Uniti [Stato]"</STRONG>, Reference(Column(:State), Reference(Column(:U.S. States))));
Come si estrae il nome del testo? Ad esempio "Stati degli Stati Uniti [Stato]"
Molto probabilmente stai riscontrando problemi perché JMP fa riferimento alla tabella dati sbagliata. Il mio suggerimento è di utilizzare SEMPRE riferimenti espliciti alle colonne -> converti sempre le colonne (riferimenti) in stringhe e poi usa formati diversi a seconda delle necessità. Nel tuo caso qualcosa del genere
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Cities.jmp");
dt_state = Open("$SAMPLE_DATA/State Abbreviations.jmp");
dt_state << New Column("Dummy", Numeric, "Continuous", Format("Best", 12));
dt_state:Abbreviations << Set Property("Link ID", 1);
dt:State << Set Property("Link Reference", Reference Table(dt_state));
dt << group columns("xy", {:X, :y});
dt << group columns("pollutants", :Ozone :: :Lead);
match_col = "X";
new_name = "coordinates";
groups_list = dt << get column groups names;
For Each({grp, ig}, groups_list,
cols = Transform Each({colweirdness}, dt << get column group(grp), AsColumn(dt, colweirdness) << get name);
For Each({colname, ic}, cols,
If(colname == match_col,
try(dt << rename column group(grp, new_name));
)
);
);