CIAO,
Sto riscontrando un problema in cui ho così tante colonne che voglio selezionare, ma non voglio digitarle tutte per crearne un nuovo sottoinsieme.
Quello che ho sono 200 colonne che iniziano tutte con la stessa stringa. Mi chiedevo se esiste un modo per selezionare queste colonne con un ciclo o un comando.
Ho provato a usare la riga:
cols = dt << Get Column Names(Starts With("Year"));
Ma se ottiene solo il nome di ogni colonna, e ho alcune colonne che non iniziano con "Anno" o addirittura hanno "Anno" nel nome. In questo momento sto creando un nuovo sottoinsieme delle colonne che voglio con:
dt2 = dt << Subset(
All rows,
columns(
:Time,
:Day,
:Name("Year 1"),
:Name("Year 2"),
:Name("Year 3"),
.
.
.
etc.
),
output table name("All Years")
);
Ci sono molte altre colonne nella mia tabella, ma voglio solo separarle. Per favore aiuto!
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />Grazie PMroz, ha funzionato alla grande!
E questo è un bel blog Dave, grazie per il link!
Questo codice farà il trucco.Bel blog Dave, btw!
dt = New Table( "Year Example",
Add Rows( 3 ),
New Column( "ABC", Numeric, Continuous, Format( "Best", 12 ), Set Values( [1, 2, 3] ) ),
New Column( "DEF", Numeric, Continuous, Format( "Best", 12 ), Set Values( [4, 5, 6] ) ),
New Column( "Year 1", Numeric, Continuous, Format( "Best", 12 ), Set Values( [7, 8, 9] ) ),
New Column( "Year 2", Numeric, Continuous, Format( "Best", 12 ), Set Values( [10, 11, 12] ) ),
New Column( "Year 3", Numeric, Continuous, Format( "Best", 12 ), Set Values( [13, 14, 15] ) )
);
col_list = dt << get column names(string);
for (i = nitems(col_list), i > 0, i--,
if (!contains(col_list[i], "Year"),
remove from(col_list, i);
);
);
dt << Subset(
Output Table( "Year Subset" ),
All rows,
columns( eval(col_list) )
);