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

Topic Options

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

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

May 11, 2017 5:32 PM
(563 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

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

May 11, 2017 5:50 PM
(560 views)

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

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

May 11, 2017 7:03 PM
(550 views)

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

May 12, 2017 3:12 PM
(521 views)

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