cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
  • New JMP features coming to desktops everywhere this September. Sign up to learn more at jmp.com/launch.
Choose Language Hide Translation Bar
SpannerHead
Level VI

Restrict For Each()

I'm fairly new to the For Each() function, so bear with me. The script below does what I need, except that I'd like to restrict the columns it acts on.  I'd like to act on columns 3 and above only?  Straightforward enough with a For() function, not sure how it works here?

 

For Each({colnames, index}, dt << Get Column Names("String"),
 rows_to_color = dt << Get Rows Where((Column(dt, colnames)[]<100));
 Column(dt, colnames) << Color Cells("Red", rows_to_color);
);

Slán



SpannerHead
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Restrict For Each()

Remove the values from the list before you start going over it

Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");
collist = dt << Get Column Names("String");
Remove From(collist, 1, 3);
show(collist);

For Each({colnames, index}, collist,
	rows_to_color = dt << Get Rows Where((Column(dt, colnames)[] < 100));
	Column(dt, colnames) << Color Cells("Red", rows_to_color);
);
-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Restrict For Each()

Remove the values from the list before you start going over it

Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");
collist = dt << Get Column Names("String");
Remove From(collist, 1, 3);
show(collist);

For Each({colnames, index}, collist,
	rows_to_color = dt << Get Rows Where((Column(dt, colnames)[] < 100));
	Column(dt, colnames) << Color Cells("Red", rows_to_color);
);
-Jarmo
jthi
Super User

Re: Restrict For Each()

You can also do it inside the for each when you define the list, but in my opinion it is better to do it before (easier to read and debug)

Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");

For Each({colname, index}, Remove(dt << Get Column Names("String"), 1, 3),
	show(colname);
);

Or if you collect list before, you can just loop over specific items

Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");
collist = dt << Get Column Names("String");

For Each({colname, index}, collist[4::N Items(collist)],
	show(colname);
);
-Jarmo
SpannerHead
Level VI

Re: Restrict For Each()

Nice!  Works well.


Slán



SpannerHead

Recommended Articles