In che modo JMP valuta una formula di colonna?@txnelson ha appena usato summary() all'interno come costante:
https://community.jmp.com/t5/Discussions/Alphabetical-Ranking-of-Nominal-Data/mp/822725/highlight/true#M100245
As Constant( Summarize( theLevels = by( :age ) ) );
Contains( theLevels, Char( :age ) );
Approccio molto interessante!
Per costante , l'indice di scripting fornisce l'esempio
Names Default To Here( 1 );
New Table( "As Constant Demo Table 1",
Add Rows( 10 ),
New Column( "Non-Constant", Formula( Random Uniform() ) ),
New Column( "Constant", Formula( As Constant( Random Uniform() ) ) )
);
this is easy to understand - As Constant( Random Uniform() ) is executed just once and the return value is used for the other rows.
The thing that puzzled me: The return value of Riassumere is empty and actually, it's theLevels which we are interested in.
Quindi, il vero trucco è
come costante : "viene eseguito solo una volta" !
molto utile!
Potrebbe essere utilizzato per:
as constant("JMP just started to evaluate column xyz");
Usiamo questo trucco per un'altra applicazione: per aprire una tabella di dati ausiliari.
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column( " col",
Formula(
as constant (
dt = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
nr = N Rows( dt );
);
Eval( (EvalExpr(myrows= dtsum << get rows where( :age == Expr(dt:age[row()])))));
Print(:age, myrows);
dtsum[myrows, 2]
)
);
Ma non è così facile come mi aspettavo...
Hm, è piuttosto tardi - non ho idea del perché:

Automazione e scriptingR: In che modo JMP valuta una formula di colonna?La domanda successiva - e quindi il titolo del post:
perché JMP elimina le voci quando chiudo dtsum ?
Try(close(dt, nosave));
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Data Table( "Big Class" ) << Sort(
By( :age, :height ),
Replace Table
);
dt << New Column( " col",
Formula(
local({tmp,myAge},
as constant (
dt0 = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
//dtsum:age << set name(age2);
nr = N Rows( dt0 );
);
myage = dt:age[row()];
Eval (Eval Expr(myrows = dtsum << get rows where( :age == Expr(myAge))));
Print(myRows);
tmp = contains(dtsum[myrows,2], :height);
if(row()==nr, dt<< runformulas();wait(1);close(dtsum, noSave);Caption("done"));
tmp
)));R: In che modo JMP valuta una formula di colonna?Il problema 1 può essere risolto tramite:
dt << New Column( " col",
Expression,
set each value (
local({tmp,myAge},
as constant (
dt0 = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
//dtsum:age << set name(age2);
nr = N Rows( dt0 );
);
myage = dt:age[row()]; // save as variable and use later here ↘:backhand_index_pointing_down:</img>
Eval (Eval Expr(myrows = dtsum << get rows where( :age == Expr(myAge))));
dtsum[myrows,2]
)));R: In che modo JMP valuta una formula di colonna?Wow, e il secondo è davvero sorprendente, può essere risolto tramite
//dense rank - with groupby
dt << New Column( " col",
set each value( // <- the first change is here
local({tmp,myAge},
as constant (
dt = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
//dtsum:age << set name(age2);
nr = N Rows( dt );
);
myage = dt:age[row()];
Eval (Eval Expr(myrows = dtsum << get rows where( :age == Expr(myAge))));
tmp = contains(dtsum[myrows,2],dt:height); // <- the second change is here : use dt:height instead of :height to force JMP to use the right table!
if(row()==nr, close(dtsum, noSave));
tmp
)));Questo risolve anche il problema con diverse voci "0" nell'approccio precedente.
Quindi, sotto la riga, le domande non erano:
perché JMP elimina i valori in dt se la tabella dtsum è chiusa?
la domanda vera e propria era:
Perché JMP usa dtsum:height invece di dt:height quando calcola le voci per la tabella dati dt ?
domanda aperta: perché dt:height risolve solo il problema per set each value() e non per formula()
R: In che modo JMP valuta una formula di colonna?Ah,
dt << New Column( "dense rank_ grouped by",
Character,
formula (
local({tmp,myAge},
as constant (
dt = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
//dtsum:age << set name(age2);
nr = N Rows( dt );
);
rw = row();
myage = dt:age[row()];
Eval (Eval Expr(myrows = dtsum << get rows where( dtsum:age == Expr(myAge)))); // <- use dtsum:age !!!
tmp = contains(dtsum[myrows,2], dt:height[rw]); // <- use dt:height !!!!
if(row()==nr, close(dtsum, noSave));
tmp
)));
@jthi , ricordo che qualche tempo fa avevi un problema simile: un conflitto se due tabelle hanno nomi di colonne sovrapposti.
Aggiungerò un link quando lo troverò...
R: In che modo JMP valuta una formula di colonna?Ti riferisci al problema che ho menzionato qui , ovvero il bug che si verifica quando si usa una combinazione di set each value, tabelle con gli stessi nomi di colonna e funzioni statistiche col all'interno di un ciclo ?
R: In che modo JMP valuta una formula di colonna?Ah, giusto, questo.
Quindi, non è solo << set each value() ad essere interessato, anche formula() può esserlo.
Che fortuna non aver trovato il tuo post di ieri.
Non avrei osato << set each value() dopo averlo letto ...
forse: non come soluzione alternativa ma come controllo incrociato.
Interessante: nel mio caso non è coinvolta alcuna statistica col (come col rank() ).
Forse JMP sa che il codice era destinato a crearne uno ; )