cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP Security Notice: CVE-2026-109618 and CVE-2026-109619

    JMP promptly initiated a review of its products, services, and relevant infrastructure for exposure to CVE-2026-109618 and CVE-2026-109619.

    Our assessment of JMP products has not identified exposure to these vulnerabilities. Where remediation was required within supporting environments, appropriate security updates and controls have been applied and validated.

    We have identified no evidence of successful exploitation or unauthorized access to JMP systems or customer information associated with these vulnerabilities.

    JMP continues to monitor the issue and relevant vendor guidance. No action is required by JMP customers at this time.

  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
screech
Level I

Increment a counter from 1 to n for every unique set of identical rows

Hi everyone,

 

I figure what I want to do is really easy, I just haven't come up with a good way to do it. I have a large table with a substantial number of identical rows which I want to rename uniquely but in a reproducible way. Currently, I have a script that takes the following column:

 

A number 1

B number 1

A number 2

A number 3

A number 3

A number 3

B number 3

B number 3

B number 3

...

 

Into into a new names column, using the row index identifier:

 

A number 1

B number 1

A number 2

A number 3

A number 3 5

A number 3 6

B number 3

B number 3 8

B number 3 9

 

 

That code is

 

Names Default To Here( 0 );
RawFile << New Column( "itemname2", Character, Nominal );
Current Data Table( RawFile );
For( i = 2, i <= N Rows( RawFile ), i++,
	If( :itemname[i] == :itemname[i - 1],
		:itemname2[i] = :itemname[i] || " " || Char( i ),
		:itemname2[i] = :itemname[i];
	);
);

 

 

This works well enough, but the issue here is I want the output to instead increment from 1 each time it needs to be used, to give something like

 

A number 1

B number 1

A number 2

A number 3

A number 3 1

A number 3 2

B number 3

B number 3 1

B number 3 2

 

I know this should be simple, but I'm not sure how to structure/limit the loop....any help would be appreciated. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
screech
Level I

Re: Increment a counter from 1 to n for every unique set of identical rows

Nevermind.....realized I just needed the initialization of the second counter outside the loop. Cheers!

 

Names Default To Here( 0 );
RawFile << New Column( "itemname2", Character, Nominal );
Current Data Table( RawFile );
k=1; For( i = 2, i <= N Rows( RawFile ), i++, If( :itemname[i] == :itemname[i - 1], :itemname2[i] = :itemname[i] || " " || Char( k );
k++, :itemname2[i] = :itemname[i];
k=1 ); );

View solution in original post

1 REPLY 1
screech
Level I

Re: Increment a counter from 1 to n for every unique set of identical rows

Nevermind.....realized I just needed the initialization of the second counter outside the loop. Cheers!

 

Names Default To Here( 0 );
RawFile << New Column( "itemname2", Character, Nominal );
Current Data Table( RawFile );
k=1; For( i = 2, i <= N Rows( RawFile ), i++, If( :itemname[i] == :itemname[i - 1], :itemname2[i] = :itemname[i] || " " || Char( k );
k++, :itemname2[i] = :itemname[i];
k=1 ); );

Recommended Articles