Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
Level V

## For Each Row () - reverse option?

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 3
Highlighted
Super User

## Re: For Each Row () - reverse option?

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
Highlighted
Level V

## Re: For Each Row () - reverse option?

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

Highlighted
Super User

## Re: For Each Row () - reverse option?

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

Article Labels

There are no labels assigned to this post.