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

- JMP User Community
- :
- Discussions
- :
- Count in a script

- 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

Nov 26, 2019 3:30 PM
(1300 views)

Hi,

I need some assistance with adding a count in a script to a new column where it counts the number of rows from n=1 to n= m (based on size of size of text file). Any thoughts / comments greatly appreciated.

Cheers,

Dennis

I need some assistance with adding a count in a script to a new column where it counts the number of rows from n=1 to n= m (based on size of size of text file). Any thoughts / comments greatly appreciated.

Cheers,

Dennis

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

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

The examples I listed before are assuming that you were adding the columns to an already existing data table. If you are creating a data table from scratch and it does not have any rows defined for it, one needs to use the

`dt << add rows(100);`

to create empty rows, before one can place values in the cells.

Here is a complete example

```
names default to here(1);
dt=new table("Example");
dt << new column( "Counter using a For Loop" );
dt << add rows(100);
For( i=1, i<= N Rows(dt), i++,
dt:Counter using a For Loop[i] = i;
);
```

Jim

7 REPLIES 7

Highlighted
##

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

Re: Count in a script

I am not sure if I really understand what you want, but if it is a simple sequence number you can easily do that multiple ways.

First, interactively. Once you create the new column, simply go to the Col Info for the new column and click on the Missing/Empty down arrow and select "Sequence Data". I will place into the new column a number from 1 to n.

Second, you can use a formula in a new column. Just create the new column, anduse the below formula to generate a sequence number for each row.

`Row()`

Jim

Highlighted
##

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

Re: Count in a script

Hi,

Sorry about not being clear. Is there a way to add the count into a script?

Sorry about not being clear. Is there a way to add the count into a script?

Highlighted
##

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

Re: Count in a script

Are either of these examples any help?

```
dt = current data table();
dt << new column( "RowNum", format( Row() ) );
dt << new column( "Counter using a For Loop" );
For( i=1, i<= N Rows(dt), i++,
dt:Counter using a For Loop[i] = i;
);
```

Jim

Highlighted
##

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

Re: Count in a script

Hi,

Thanks for the suggestion.

I am trying to get it to work, but it still does not generation a column

with number 1,2,3,....etc.

I will keep trying.

Cheers,

Thanks for the suggestion.

I am trying to get it to work, but it still does not generation a column

with number 1,2,3,....etc.

I will keep trying.

Cheers,

Highlighted

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

The examples I listed before are assuming that you were adding the columns to an already existing data table. If you are creating a data table from scratch and it does not have any rows defined for it, one needs to use the

`dt << add rows(100);`

to create empty rows, before one can place values in the cells.

Here is a complete example

```
names default to here(1);
dt=new table("Example");
dt << new column( "Counter using a For Loop" );
dt << add rows(100);
For( i=1, i<= N Rows(dt), i++,
dt:Counter using a For Loop[i] = i;
);
```

Jim

Highlighted
##

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

Re: Count in a script

Thank you, that's awesome! I got it to work.

I just have one more question. If I don't know the exact number of rows

generated (due to text file size variation), is there a way to read the

text file and have the exact rows for the counter?

I just have one more question. If I don't know the exact number of rows

generated (due to text file size variation), is there a way to read the

text file and have the exact rows for the counter?

Highlighted
##

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

Re: Count in a script

Thanks for that, works great!

Much appreciated.

Cheers,

Much appreciated.

Cheers,

Article Labels

There are no labels assigned to this post.