cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

Solve problems, and share tips and tricks with other JMP users.
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