Hi everybody,
I would like to select rows based on the entries of selected rows from another table. Below a code snippet. The last row is not valid, but it should clarify what I mean.
selected_row_idx = DT << Get Selected Rows;
measurement_starts = DT:MeasurementStart[selected_row_idx];
measurement_ends = DT:MeasurementEnd[selected_row_idx];
DTmeas << Select Where(measurement_starts[1] <= :TimeStamp <= measurement_ends[1] & measurement_starts[2] <= :TimeStamp <= measurement_ends[2] & ... & measurement_starts[n] <= :TimeStamp <= measurement_ends[n]);
How can I write the last row in some dynamical way, so that I have as many conditions there connected with "&" as I have rows selected in table DT? I could write a loop and filter subsets iteratively, but this is kind of lame. Or I could put together the last row as a string and parse and execute it, but that is not nice, either. Is there an elegant way to do this?
I think you could use matrices, sql, building expression,...
Names Default To Here(1);
dt1 = New Table("Untitled",
Add Rows(3),
Compress File When Saved(1),
New Column("A", Numeric, "Continuous", Format("Best", 12), Set Values([1, 1, 5])),
New Column("B", Numeric, "Continuous", Format("Best", 12), Set Values([2, 3, 6]))
);
dt1 << Select Rows(1::3);
starts = dt1[dt1 << get selected rows, {"A"}];
ends = dt1[dt1 << get selected rows, {"B"}];
dt1 << clear select;
dt2 = New Table("Untitled 2",
Add Rows(5),
Compress File When Saved(1),
New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4, 5]))
);
dt2 << Select Where(
N Items(Loc((starts <= :Column 1)` + (ends >= :Column 1)` >= 2)) > 0
)