Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Loops Question

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Loops Question

Created:
May 11, 2017 5:32 PM
| Last Modified: May 11, 2017 5:32 PM
(3786 views)

Hello,

I want to fill rows with 1,2,3,4, ... I know I can use row functions, but I am practicing some simple coding.

I am writing the code below in the column formula, and it fills the rows of my Test column 1,2,3,... but last row is empty. Can anyone please point out the issue? I will eventually write script in script window, but right now just practicing in column formula...

a = N Row();

For( i = 1, i <= a, i++,

Row() = i;

:Test = i;

);

Thanks!

3 REPLIES 3

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Loops Question

Created:
May 11, 2017 5:50 PM
| Last Modified: May 11, 2017 6:04 PM
(3783 views)
| Posted in reply to message from aumair 05-11-2017

Here is a simple example of what you want to do:

```
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\big class.jmp" );
dt << New Column( "Test" );
a = N Row( dt );
For( i = 1, i <= a, i++,
dt:Test[i] = Floor( Mod( i, 4 ) );
If( Floor( Mod( i, 4 ) ) == 0,
dt:Test[i] = 4
);
);
```

Here is the same thing as a formula

If( Floor( Mod( Row(), 4 ) ) == 0,

4,

Floor( Mod( Row(), 4 ) )

)

Formulas automatically cycle through all rows

Jim

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Loops Question

Thanks for the help Jim!

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Loops Question

Created:
May 12, 2017 3:12 PM
| Last Modified: May 12, 2017 3:14 PM
(3744 views)
| Posted in reply to message from aumair 05-11-2017

I echo what Jim said. Column Formulas are essentially an implicit loop over all rows in the table. So, in your case, to create a column that numbers every row, the column formula for the TEST column is simply:

`Row()`

This will number each row of the TEST column from 1 through the end of the table.

If you were to use direct scripting from a script window:

`For( i = 1, i <= N Row(), i++, :Test[i] = i );`

PDB

Article Labels

There are no labels assigned to this post.