Subscribe Bookmark RSS Feed

For Each Row () - reverse option?

djhanson

Community Trekker

Joined:

Jun 23, 2011

The answer is probably no, but I thought I'd ask anyways

Question: is there any way to make For Each Row() go in reverse (from bottom to top)?  Like --

It works slick and fast, but of course it's working top to bottom.  I need to delete some rows and one always wants to do this in reverse of course.

thanks, DJ

3 REPLIES
Phil_Brown

Super User

Joined:

Mar 20, 2012

I wouldn't use For Each Row() to delete rows. I think an even faster method would be to use DeleteRows. ​For example, if one wanted to delete rows where Column(1) has missing values, one could do the following:

dt = current data table();

rowsToDelete = dt << Get Rows Where( Is Missing(:Column 1[]) );

If( NRows( rowsToDelete ) != 0,

     dt << Delete Rows( rowsToDelete );

);

You can supply the conditional clause you'd need within the Get Rows Where().

Hope this helps!

Best,

Phil

PDB
djhanson

Community Trekker

Joined:

Jun 23, 2011

Hi Phil, great idea!  that looks even better - I will give it a try.  cheers, DJ

ron_horne

Super User

Joined:

Jun 23, 2011

hi djhanson​,

Philip Brown is write. his method is not only faster but more reliable.

regarding the reverse way, you can try this option:

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

For( i = N Rows( dt ), 1 >= 1, i--,

       dt << select where( Row() == i );

       dt << delete rows;

       Wait( 1.5 );

);

best,

ron