Sto lavorando per raggruppare diverse migliaia di colonne in base al nome che corrisponde a qualcosa da un elenco di valori di una colonna iniziale
esempio:
Valori Col1 = {passaggio1, passaggio2, passaggio3}
Col2:5000 nomi: step1_blahblahblah, step2_blahblbahblah, ecc.
Immagino di non essere del tutto sicuro di come definire l'istruzione if(contain) che utilizza l'elenco di valori di Col1.
dt = current data table();
Summarize( dt, StepIDIndex= by( :RecipeStepId) );//get list of unique RecipeStepID's
colNamesList = dt << get column names(string, continuous); //get all the column names
StepList = {}; //Create an empty list for the matching columns
// Find matching column names
For( i = 1, i <= N Items( colNamesList ), i++,
If(
contains( colNamesList[i], StepIDIndex),
Insert Into( StepList , colNamesList[i] )
)
);
// If groups of columns are found, create col groupings
If( N Items( StepList ) > 0,
dt<< select columns( StepList );
dt<< group columns();
);
Se i nomi delle colonne (?) hanno sempre il formato step1_something, puoi usare Word per separare il passaggio dal resto della stringa per semplificare il confronto. Di seguito è riportato un esempio di ciò che penso che vorresti fare (richiede JMP16 a causa di For Each):
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(3),
Set Header Height(44),
New Column("Col1", Character, "Nominal", Set Values({"step1", "step2", "step3"})),
New Column("step1_a", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
New Column("step1_b", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
New Column("step1_c", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
New Column("step2_a", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
New Column("step2_b", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .]))
);
Summarize(dt, uniq_vals = by(:col1));
col_list = dt << get column names(string, continuous);
//initialize col group collector associative array
col_groups = Repeat({{}}, N Items(uniq_vals));
For Each({col_name}, col_list,
found_idx = Contains(uniq_vals, Word(1, col_name, "_"));
If(found_idx,
Insert Into(col_groups[found_idx], col_name);
);
);
For Each({col_group, idx}, uniq_vals,
If(N Items(col_groups[idx]) > 0,
Eval(EvalExpr(dt << Group Columns(col_group, Expr(col_groups[idx]))));
);
);