I need a JSL loop that will search the column headers of a data table, and if the column header has "(rad)" in it, I'd like to multiply all of the values in that column by 180/pi, and then change "(rad)" to "(deg)" in the column header.
I have tried everything I can think of -- including chatGPT -- but so far no luck.
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(2),
Compress File When Saved(1),
New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([., .])),
New Column("a (rad)", Numeric, "Continuous", Format("Best", 12), Set Values([1, .]))
);
colnames = dt << Get Column Names(Continuos, "String");
dt << Begin Data Update();
For Each({colname}, colnames,
If(Contains(colname, "(rad)"),
For Each Row(dt, Column(dt, colname)[] = Column(dt, colname)[] * 180 / Pi());
Column(dt, colname) << Set Name(Substitute(colname, "(rad)", "(deg)"));
)
);
dt << End Data Update();
Write();
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(2),
Compress File When Saved(1),
New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([., .])),
New Column("a (rad)", Numeric, "Continuous", Format("Best", 12), Set Values([1, .]))
);
colnames = dt << Get Column Names(Continuos, "String");
dt << Begin Data Update();
For Each({colname}, colnames,
If(Contains(colname, "(rad)"),
For Each Row(dt, Column(dt, colname)[] = Column(dt, colname)[] * 180 / Pi());
Column(dt, colname) << Set Name(Substitute(colname, "(rad)", "(deg)"));
)
);
dt << End Data Update();
Write();
Always impressive, thank you!
A few follow-on questions:
Thank you again!
As Column(dt, colname) = As Column(dt, colname) * 180 / Pi()