cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
Choose Language Hide Translation Bar

How do i extract the number of levels from a distribution

Hi all,

I would like to get a JMP Script that allows me to extract the value that i highlighted in the red box and to put it into a column of a new table. PS: I know that it is possible to generate a table from the distribution with the command Make into Data Table but this command does not work on the number in the box. 

Screenshot 2024-09-04 095200.png

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How do i extract the number of levels from a distribution

Here is an example of one way to do this

names default to here(1);

dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );

summarize( dt, levels = By( :Age ) );

dtNew = New Table( "Count", 
	Add Rows( 1 ),
	New Column( "Count" )
);

dtNew:Count[1] = N Items( Levels );

Here is a second example that reads the Frequencies table directly and count the number of rows

names default to here(1);

dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );

// Report snapshot: Big Class - Distribution of sex
dis = Data Table( "Big Class" ) << Distribution( Nominal Distribution( Column( :age ) ) );

dtNew = New Table( "Count2", 
	Add Rows( 1 ),
	New Column( "Count" )
);

// Calculate the number of items in the Frequencies table, minus the 
// the last row which is the Totals row
tableLevels = N Items( report(dis)["Frequencies",StringColBox(1)] << get ) - 1;
dtNew:Count[1] = tableLevels;

 

Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: How do i extract the number of levels from a distribution

Here is an example of one way to do this

names default to here(1);

dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );

summarize( dt, levels = By( :Age ) );

dtNew = New Table( "Count", 
	Add Rows( 1 ),
	New Column( "Count" )
);

dtNew:Count[1] = N Items( Levels );

Here is a second example that reads the Frequencies table directly and count the number of rows

names default to here(1);

dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );

// Report snapshot: Big Class - Distribution of sex
dis = Data Table( "Big Class" ) << Distribution( Nominal Distribution( Column( :age ) ) );

dtNew = New Table( "Count2", 
	Add Rows( 1 ),
	New Column( "Count" )
);

// Calculate the number of items in the Frequencies table, minus the 
// the last row which is the Totals row
tableLevels = N Items( report(dis)["Frequencies",StringColBox(1)] << get ) - 1;
dtNew:Count[1] = tableLevels;

 

Jim

Re: How do i extract the number of levels from a distribution

After my question I managed to write the code with method two on my own but method one seems more convenient and immediate. Thank you!