Assegna i valori contenuti nell'elencoCIAO,
questo problema mi lascia davvero perplesso.
Voglio assegnare valori dalla tabella 1 (dt_group) alla tabella 2 (dt_subset).
Quindi, scorrere ogni riga della Tabella 2 e quindi confrontare le righe della colonna Prodotto della tabella 2 con ogni riga della tabella 1 ProductGroups e quindi assegnare i valori Limits alla colonna _LIMITS nella tabella 1 se viene trovato un sting corrispondente. Come potrei scrivere questo script?
tabella 1:

tabella 2:

Ho già provato ma ho problemi a confrontare le stringhe di entrambe le tabelle...
Names Default To Here( 1 );
dt_subset = Current Data Table();
col_names = dt_subset << get column names( string );
dt_group = Data Table( "dt_groups" );
aa_limits = Associative Array( dt_group:Tests << get values, dt_group:Limits << get values );
For( i = 1, i <= N Items( aa_limits ), i++,
If( Contains( aa_limits, col_names[i] ),
curname = Column( dt_subset, col_names[i] ) << get name;
new_col = dt_subset << New Column( (curname || "_LIMITS"),
Numeric,
Continuous,
Format( "Percent", 12, 2 )
);
dt_subset << Move Selected Columns( new_col, After( Column( dt_subset, curname ) ) );
)
);
Grazie,
J
Automazione e scriptingRe: Assegna valori contenuti nell'elencoGrazie Jim e Jarmo!
Ecco un altro metodo che ho usato per capirlo.
Names Default To Here( 1 );
dt_subset = Data Table( "subset table.jmp" );
dt_group = Data Table( "dt_groups.jmp" );
list1 = dt_group:Limits << get values;
list2 = dt_group:ProductGroups << get values;
list3 = dt_group:Tests << get values;
col_names = dt_subset << get column names( string );
aa_limits = Associative Array( dt_group:Tests << get values, dt_group:Limits << get values );
For Each( {val1, idx1}, list2,
For Each Row(
dt_subset,
For Each( {val3, idx2}, list3,
If( Contains( val1, dt_subset:Product ),
As Column( dt_subset, list3[idx1] || "_LIMITS" ) = list1[idx1]
)
)
);
);
Re: Assegna valori contenuti nell'elencoEcco il mio tentativo. Utilizza le tabelle fornite, quindi non crea nuove colonne e imposta solo temporaneamente le formule per calcolare i valori (molto probabilmente può essere semplificato parecchio se la tabella del sottoinsieme non ha colonne pre-create)
Names Default To Here(1);
dt_subset = Open("$DOWNLOADS/subset table.jmp");
dt_group = Open("$DOWNLOADS/dt_groups.jmp");
aa_tests = Associative Array();
For Each Row(dt_group,
limitname = :Tests || "_LIMITS";
aa_tests[limitname] = Associative Array();
aa_tests[limitname]["Groups"] = Words(:ProductGroups, " ,");
aa_tests[limitname]["Limit"] = :Limits
);
colnames = dt_subset << Get Column Names("Continuous", "String");
For Each({{testname, specs}}, aa_tests,
If(!Contains(colnames, testname),
Write("\!NNo Match: " || testname);
Continue();
);
Column(dt_subset, testname) << Formula(
If(Contains(specs["Groups"], :Product),
specs["Limit"];
,
.
);
);
dt_subset << run formulas;
Column(dt_subset, testname) << Delete Formula;
);
Re: Assegna valori contenuti nell'elencoEcco un approccio completamente diverso. Utilizza le capacità di Join in JMP anziché tentare di fare tutto con loop e confronti. Credo che vada come vuoi, ma verifica i risultati.
</CODE></PRE>
<PRE><CODE class=" language-jsl">Names Default To Here( 1 );
dt_subset = Data Table( "subset table" );
col_names = dt_subset << get column names( string,continuous );
dt_group = Data Table( "dt_groups" );
// Expand dt_group:ProductGroups into separate columns
dt_group << text to columns( delimiter( "," ), columns( :ProductGroups ) );
// Stack the resulting columns
dt_group_col_names = dt_group << get column names( string );
// Remove the first 3 columns from the list
Remove From( dt_group_col_names, 1, 3 );
// Stack data table
// → Data Table( "Stacked dt_groups" )
dt_stack_group = dt_group << Stack(
columns( dt_group_col_names ),
Source Label Column( "Label" ),
Stacked Data Column( "Product" ),
"Non-stacked columns"n( Keep( :Tests, :Limits ) ),
Output Table( "Stacked dt_groups" )
);
// Get rid of the Label column
dt_stack_group << delete columns( :Label );
// Stack the subset table
// Add a RowNum column to the table to preserve the order
dt_subset << New Column( "RowNum", set each value( Row() ) );
dt_stack_subset = dt_subset << Stack(
columns(
col_names
),
Source Label Column( "Tests" ),
Stacked Data Column( "Data" ),
Name("Non-Stacked columns")(Keep({Product, RowNum})),
Output Table( "Stack of subset table" )
);
// Join the 2 stacked tables
dt_joined = dt_stack_subset << Join(
With( dt_stack_group ),
Merge Same Name Columns,
Match Flag( 0 ),
By Matching Columns( :Product = :Product, :Tests = :Tests ),
Drop multiples( 0, 0 ),
Include Nonmatches( 1, 0 ),
Preserve main table order( 1 ),
Output Table( "Joined stack data" )
);
// Split the table back to original form
dt_final = dt_joined << Split(
Split By( :Tests ),
Split( :Data, :Limits ),
Group( :RowNum ),
Output Table( "Final" ),
Sort by Column Property
);
// Cleanup and rearrange the Final data table
dt_final << delete columns( :RowNum );
// Rename the columns
For( i = 2, i <= N Cols( dt_final ), i++,
theName = Column( dt_final, i ) << get name;
If(
Starts With( theName, "Data" ), Column( dt_final, i ) << set name( Substr( theName, 6 ) ),
Starts With( theName, "Limits" ),
Column( dt_final, i ) << set name( Substr( theName, 8 ) || "_LIMITS" )
);
);
// Reorder the columns
For( i = Length( col_names ), i >= 1, i--,
If( Try( Column( dt_final, col_names[i] || "_LIMITS" ) << get name, "" ) != "",
theName = ":\!"" || col_names[i] || "_LIMITS" || "\!"n";
Eval( Parse( "dt_final << Move Selected Columns( " || theName || ",to first);" ) );
//dt_final << Move Selected Columns( :"Test5^0.8_LIMITS"n,to last)
);
theName = ":\!"" || col_names[i] || "\!"n";
Eval( Parse( "dt_final << Move Selected Columns( " || theName || ",to first);" ) );
);
dt_final << move selected columns( :Product, to first );
close( dt_stack_group, nosave);
close( dt_stack_subset, nosave);
close( dt_joined, nosave);Re: Assegna valori contenuti nell'elencoGrazie, Jim! Non è esattamente quello che sto cercando.
Un esempio:
confrontare la riga 1 della colonna Prodotto della tabella 2 con tutte le stringhe nella prima riga di ProductGroups e quindi assegnare il valore limite corrispondente

Re: Assegna valori contenuti nell'elencoEcco come farei ciò che hai specificato
Names Default To Here( 1 );
dt_subset = Current Data Table();
col_names = dt_subset << get column names( string );
dt_group = Data Table( "dt_groups" );
//aa_limits = Associative Array( dt_group:Tests << get values, dt_group:Limits << get values );
For( i = 1, i <= N Rows( dt_group ), i++,
found = Contains( col_names, dt_group:Tests[i] );
If( found > 0,
//curname = Column( dt_subset, col_names[i] ) << get name;
Eval(
Eval Expr(
new_col = dt_subset << New Column( col_names[found] || "_LIMITS",
Numeric,
Continuous,
Format( "Percent", 12, 2 ),
set each value( Expr( dt_group:limits[i] ) )
)
)
);
dt_subset << Move Selected Columns( new_col, After( Column( dt_subset, col_names[found] ) ) );
)
);
Assicurati che i tuoi nomi nella colonna dt_group:tests corrispondano ai nomi delle colonne. Potresti avere degli spazi vuoti extra nei nomi delle colonne rispetto ai valori dei Test.