cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use to use Text Explorer to glean valuable information from text data at April 25 webinar.
Choose Language Hide Translation Bar
View Original Published Thread

Restrict For Each()

SpannerHead
Level V

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 V


Re: Restrict For Each()

Nice!  Works well.


Slán



SpannerHead