One option would be to use << Set Each Value()
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(4),
New Column("a", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4])),
New Column("b", Numeric, "Continuous", Format("Best", 12), Set Values([5, 6, 7, 8])),
New Column("a2", Numeric, "Continuous", Format("Best", 12), Set Values([11, ., 33, 44])),
New Column("b2", Numeric, "Continuous", Format("Best", 12), Set Values([., ., 77, .]))
);
wait(2); // demo purposes
new_cols = {"a2", "b2"};
old_cols = {"a", "b"};
For(i = 1, i <= N Items(old_cols), i++,
Column(dt, new_cols[i]) << Set Each Value(
If(Is Missing(AsColumn(Column(dt, new_cols[i]))),
AsColumn(Column(dt, old_cols[i]))
,
AsColumn(Column(dt, new_cols[i]))
)
)
);
I think you have to provide Column with [] or [Row()] if you want to add values like you suggested
For(k = 1, k <= Length(old_cols), k++,
For Each Row(
new_col_val = Column(dt, new_cols[k])[];
old_col_val = Column(dt, old_cols[k])[];
Column(dt, new_cols[k])[] = If(Is Missing(new_col_val), old_col_val, new_col_val)
)
);
or use As Column
For(k = 1, k <= Length(old_cols), k++,
For Each Row(
new_col_val = AsColumn(dt, new_cols[k]);
old_col_val = AsColumn(dt, old_cols[k]);
AsColumn(dt, new_cols[k])[] = If(Is Missing(new_col_val), old_col_val, new_col_val)
)
);
-Jarmo