cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Instantly extract effect sizes, F-ratios, and FDR-adjusted p-values from your models with the Calculate Effects Sizes extension, available now in the JMP Marketplace!
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

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

how do a number sequence to unique values?

I have the  following Column1 and need to create a new column containing the sequential number of repetitions in Column1

 

Column1
a
a
a
b
b
c

 

The resulting table should look like this:

Column1Column2
a1
a2
a3
b1
b2
c1

 

Any suggestions how to code in in JSL? (or in column formula?) thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
gzmorgan0
Super User (Alumni)

Re: how do a number sequence to unique values?

Here is a column formula method:

// define values 
Col1Vals = {"a","a","a","a","b","b","c","c","c"}; 

dt = New Table(); 

dt << New Column("MyValues",Character,Nominal,<< Set Values(Col1Vals)); 

// Create Cumulative Frequencies
dt << New Column("CumulativeFreqCount",Numeric,Continuous); 
dt:CumulativeFreqCount << Set Each Value(
If(
	Row() == 1, 1,
	:MyValues == Lag( :MyValues, 1 ), Lag(:CumulativeFreqCount, 1 ) + 1,
	1
)); // end set each value

View solution in original post

4 REPLIES 4
uday_guntupalli
Level VIII

Re: how do a number sequence to unique values?

@rs , 

 Assuming you have a reference to the data table - let us say dt : 

 

dt1 = dt << Summary(
	Group( :Column 1 ),
	Freq( "None" ),
	Weight( "None" )
)

If the data is not sorted (typically it should), then you can use the sort() on the resulting table 

Best
Uday
rs
rs
Level II

Re: how do a number sequence to unique values?

thank you.  I put the code into a JMP script file (see attachment) but the script does not run.  Any suggestions? 

Would be easier to put the code in a column formula?

uday_guntupalli
Level VIII

Re: how do a number sequence to unique values?

Actually, I missed the part where you wanted to get a cumulative sum, rather just the sum.

 

I am pretty sure there is smarter and more efficient ways to do this. This will work though. 

I am essentially creating the raw data as well, for you to test and play with

 

// define values 
Col1Vals = {"a","a","a","a","b","b","c","c","c"}; 

dt = New Table(); 

dt << New Column("MyValues",Character,Nominal,<< Set Values(Col1Vals)); 

// Generate summary 

dt1 = dt << Summary( Group( :MyValues ), Freq( "None" ), Weight( "None" ) );

UniqueItems = dt1:MyValues << Get values; 
FrequencyOfItems = dt1 << Get As Matrix; 

Close(dt1,"No Save"); // Add Cumulative Frequencies back dt << New Column("CumulativeFreqCount",Numeric,Continuous); for(i = 1, i <= N Items(UniqueItems),i++, Rows = dt << Select Where(:MyValues == UniqueItems[i]) << Get Selected Rows; ValsToAppend = Transpose(Index(1,FrequencyOfItems[i])); dt[Rows,"CumulativeFreqCount"] = ValsToAppend; dt << Clear Select; );

image.png

Best
Uday
gzmorgan0
Super User (Alumni)

Re: how do a number sequence to unique values?

Here is a column formula method:

// define values 
Col1Vals = {"a","a","a","a","b","b","c","c","c"}; 

dt = New Table(); 

dt << New Column("MyValues",Character,Nominal,<< Set Values(Col1Vals)); 

// Create Cumulative Frequencies
dt << New Column("CumulativeFreqCount",Numeric,Continuous); 
dt:CumulativeFreqCount << Set Each Value(
If(
	Row() == 1, 1,
	:MyValues == Lag( :MyValues, 1 ), Lag(:CumulativeFreqCount, 1 ) + 1,
	1
)); // end set each value

Recommended Articles