Ri: Script per convertire una stringa da un elenco nel corpo di una formula in una nuova colonna.In questo esempio tutte le "formule" hanno un nome di colonna che inizia dopo "(" quindi puoi sostituirlo con "(:" e poi usare Parse
Names Default To Here(1);
dtinit = Open("$SAMPLE_DATA/Bands Data.jmp");
dtfeat = New Table("features",
Add Rows(14),
New Column("Term",
Character,
"Nominal",
Set Property("ID Column", 1),
Set Values(
{"press speed", "(roller durometer-34.5151)*(anode space ratio-102.914)", "(proof cut-44.9671)*(blade pressure-30.8904)",
"(anode space ratio-102.914)*(chrome content-99.6164)", "(humidity-78.6849)*(press speed-1851.21)", "roller durometer",
"(roller durometer-34.5151)*(current density-39.0164)", "(humidity-78.6849)*(wax-2.4037)",
"(wax-2.4037)*(chrome content-99.6164)", "(viscosity-50.7836)*(press speed-1851.21)", "(wax-2.4037)*(hardener-0.96014)",
"(roughness-0.71969)*(current density-39.0164)", "(humidity-78.6849)*(ink pct-55.6473)",
"(blade pressure-30.8904)*(press speed-1851.21)"}
)
),
Set Label Columns(:Term)
);
dtfeat << New Column("interaction", Character, "Nominal", Formula(If(Starts With(:term, "("), :term, ""))) <<
Move Selected Columns({:interaction}, after(:term));
value = dtfeat:interaction << get values();
uniqueinteraction = Associative Array(value) << get keys;
For Each({uniq}, uniqueinteraction,
f_str = Substitute(uniq, "(", "(:");
If(IsMissing(f_str),
continue();
);
Eval(EvalExpr(
dtinit << New Column(uniq, Numeric, "Continuous",
Formula(Expr(Parse(f_str)))
)));
);
Inserisci un'espressione in un'altra usando Eval Insert, Eval Expr, Parse e Substitute
Ri: Script per convertire una stringa da un elenco nel corpo di una formula in una nuova colonna.Eccezionale. Ha fatto il trucco. Molte grazie.
Script per convertire una stringa da un elenco nel corpo di una formula in una nuova colonna.Seguendo il processo di identificazione di alcune colonne interagenti dopo aver utilizzato la piattaforma fit e cercando qualche interazione (fattoriale...). Voglio utilizzare il termine risultante (come cA*0.1+cB*0.3) dall'interazione come punto di partenza per creare automaticamente formule di colonna da quei termini. Faccio fatica a trovare un modo per utilizzare il contenuto di una stringa come "cA*0.1+cB*0.3" dove cA e cB rappresentano i nomi di 2 colonne presenti in una tabella per costruire nuove formule.
L'ultima parte dello script crea la formula ma rappresenta solo il contenuto della stringa invece di valutarne il contenuto.
Qualsiasi suggerimento sarebbe molto apprezzato.
Sebastiano
names default to here(1);
clear log();
dtinit=Open( "$SAMPLE_DATA/Bands Data.jmp" );
// Make TableBox into a Data Table
// → Data Table( "Untitled 3" )
//terms tables resulting from a generalized regression taking into consideration term interaction.
dtfeat = New Table( "features",
Add Rows( 14 ),
New Column( "Term",
Character,
"Nominal",
Set Property( "ID Column", 1 ),
Set Values(
{"press speed", "(roller durometer-34.5151)*(anode space ratio-102.914)", "(proof cut-44.9671)*(blade pressure-30.8904)",
"(anode space ratio-102.914)*(chrome content-99.6164)", "(humidity-78.6849)*(press speed-1851.21)", "roller durometer",
"(roller durometer-34.5151)*(current density-39.0164)", "(humidity-78.6849)*(wax-2.4037)", "(wax-2.4037)*(chrome content-99.6164)",
"(viscosity-50.7836)*(press speed-1851.21)", "(wax-2.4037)*(hardener-0.96014)", "(roughness-0.71969)*(current density-39.0164)",
"(humidity-78.6849)*(ink pct-55.6473)", "(blade pressure-30.8904)*(press speed-1851.21)"}
)
),
Set Label Columns( :Term )
);
//Identifies interacting terms
// New column: interaction
dtfeat << New Column( "interaction", Character, "Nominal", Formula( If( Starts With( :term, "(" ), :term, "" ) ) ) <<
Move Selected Columns( {:interaction}, after( :term ) );
value = dtfeat:interaction << get values();
uniqueinteraction = Associative Array( value ) << get keys;
nvinteract = N Items( uniqueinteraction );
//Will create a column named after the interacting terms
//Should apply a formula based on the interacting terms
//However, not sure how to extract the string from the list 'uniqueinteraction' so that is it not seen as a string but rather as 'formula instruction' where some portion of the term is recognized as a column namealready present in the original table
For( i = 1, i <= nvinteract, i++,
dtinit << New Column( uniqueinteraction[i], Numeric, "Continuous", Format( "Best", 12 ), Formula( Eval( uniqueinteraction[i] ) )
Consumatori e ricerche di mercato