Hallo,
Ich lerne, mit Ausdrucksmanipulationen zu arbeiten, und es fällt mir schwer, mich damit auseinanderzusetzen.
Im ersten Abschnitt des folgenden Codes kann ich den Spaltennamen der Zeichenfolge erfolgreich in den Ausdruck column() einfügen, aber ich kann die generierten Ausdrücke nicht in eine Liste einfügen.
Der zweite Abschnitt zerlegt Interaktionsterme (dies ist eine Effektliste von SLS), fügt sie in ihren eigenen column()-Ausdruck ein, setzt sie wieder als Interaktionsterm zusammen und fügt diesen dann in eine Liste ein.Dieser Abschnitt funktioniert nicht.
Hat jemand hilfreiche Tipps oder sieht etwas, das ich in Bezug auf die Funktionsweise von Ausdrucksmanipulationen falsch verstehe?Danke im Voraus!
names default to here(1);
// Basic need below - but only works for single column names
collist = { "Col 1", "Col 2", "Col 3", "Col 4", "Col 5" };
newlist = {};
for( i = 1, i <= N items(collist), i++,
// Empty arg to identify cols by names
name_arg = Expr( column() );
insert into( name_arg, eval insert( collist[i] ) ); // result: column("Col 1"), or other cols inserted <-- Working as intended
show( name_arg ); // Shows successful insert into's
insert into( newlist, insert into( name_arg, eval insert( collist[i] ) ) );
// Nested insert into doesn't work
// Need to insert the result of the first insert into, into newlist
);
show( newlist ); // Currently shows empty list
///////////////////////////////////////// DOES NOT WORK, BELOW
// Advanced flow - interaction detection
collist2 = { "Col 1", "Col 2", "Col 3", "Col 4", "Col 5", "Col 1*Col 2", "Col 2*Col 4", "Col 5*Col 5" };
newlist2 = {};
for( a = 1, a <= N items( collist2 ), a++,
// Empty arg to identify cols by names
name_arg = Expr( column() );
// For whatever the match below, the result must be added to newlist2
// Regex works, as per regex101.com
if( !contains( collist2[a], "*" ), insert into( name_arg2, eval insert( collist2[a] ) ), // single term insert, refer to basic needs flow above
insert into( name_arg2, eval insert( regex( collist2[a], "^(.*)\*(.*)$", "\1" ) ) ); // Breaks apart 1st group to insert into column()
insert into( name_arg2, eval insert( regex( collist2[a], "^(.*)\*(.*)$", "\2" ) ) ); // Breaks apart 2nd group to insert into column()
// The line below is a mockup of joining back together the first and second group together as interaction terms - doesn't work
//eval expr( expr( insert into( name_arg2, eval insert( regex( mylist2[a], "^(.*)\*(.*)$", "\1" ) ) )*insert into( name_arg2, eval insert( regex( mylist2[a], "^(.*)\*(.*)$", "\2" ) ) );
)
);
Desired_output = { column("Col 1"), column("Col 2"), column("Col 3"), column("Col 4"), column("Col 5"), column("Col 1")*column("Col 2"),
column("Col 2")*column("Col 4"), column("Col 5")*column("Col 5") };