cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Robbb
Level III

How to filter rows of a data table with dynamical number of conditions?

 

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to filter rows of a data table with dynamical number of conditions?

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
)
-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: How to filter rows of a data table with dynamical number of conditions?

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
)
-Jarmo
Robbb
Level III

Re: How to filter rows of a data table with dynamical number of conditions?

Very nice, thank you!

Recommended Articles