cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP 19 is here! See the new features at jmp.com/new.
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
Choose Language Hide Translation Bar
Thierry_S
Super User

JMP 17.2 > CUSTOMIZED REPORT > STRING COL BOX > How do I distribute a long list into multiple columns?

Hi JMP Community,

 

I am experimenting with a custom report (see below), for which I would like to distribute lists of varying length into multiple columns in a String Col Box(). For example, for the list shown in the script, I would like to distribute its elements into 4 columns of 17 lines.

 

The simplified script (I stripped everything but the essential lines):

Names Default to Here (1);

datastring = {	"ASPM", "AURKA", "AURKB", "BIRC5", "BUB1", "BUB1B", "CCNB1", "CCNB2", "CCNE2", "CDC20", "CDC6", "CDCA2", "CDCA5", "CDCA8", "CDK1", "CDT1", 
				"CENPE", "CENPF", "CENPK", "CENPN", "CENPS", "CENPW", "DIAPH3", "DLGAP5", "ECT2", "ESCO2", "FAM83D", "HJURP", "KIF11", "KIF14", "KIF15", "KIF18A", 
				"KIF18B", "KIF23", "KIF2C", "KIF4A", "KIFC1", "KNL1", "MAD2L1", "MKI67", "NCAPG", "NCAPH", "NDC80", "NEK2", "NUF2", "NUSAP1", "OIP5", "PLK1", "PRC1", "PSRC1", 
				"PTTG1", "RACGAP1", "SGO1", "SGO2", "SKA1", "SKA3", "SPAG5", "SPC24", "SPC25", "TACC3", "TOP2A", "TPX2", "TRIP13", "TTK", "UBE2C", "UHRF1", "ZWILCH", "ZWINT"};

// The length of the list varies from 4 to 125 items, depending on the specific report

rep_w = New Window ("REPORT TEST",
	
	mainframe = HList Box("DATA",
		
		text_data = TableBox (Col Span Box ("MEMBERS", String Col Box ("Genes", datastring)))
		
	)
);

Thank you.

 

Best regards,

 

TS

 

Thierry R. Sornasse
1 ACCEPTED SOLUTION

Accepted Solutions

Re: JMP 17.2 > CUSTOMIZED REPORT > STRING COL BOX > How do I distribute a long list into multiple columns?

@Thierry_S 

Here is a generalized way to do it in JSL. I created a function the requires an original list and an integer. The function splits the original list into n number of smaller lists and returns the list of lists. In the case that the number of items in the original list is not evenly divisible by n, the nth column will have the balance of items. This keeps the function general in case you want to use it again for a table with more or less columns. 

The table is then created by appending each list as a string col box to a table box:

Names Default to Here (1);

splitList_fxn = function( {list, n}, 

	// split a list into into n evenly divided lists and return a list of lists
	// if list items/n is not an integer, place the extra items in the nth column

	{i,j,k,n,lists,thisList,listSize,items},
	
	lists = {};
	items = n items( list );
	listSize = round( items/n );
	
	k = 0; // counter
	for( i = 1, i <= n, i++,
		thisList = {};
		if( i != n,
		
			// all but the last list
			for( j = (k*listSize)+1, j <= listSize*i, j++, 
				insert into( thisList, list[j] )
			),
			
			// last list will be the remaining items in case there is a remainder
			for( j = (k*listSize)+1, j <= items, j++,
				insert into( thisList, list[j] )
			)
		);
		k++;
		insert into( lists, eval list( list( thisList ) ) )
	);
	return( lists )
);

// number of columns
n = 4;

// original list
datastring = {	"ASPM", "AURKA", "AURKB", "BIRC5", "BUB1", "BUB1B", "CCNB1", "CCNB2", "CCNE2", "CDC20", "CDC6", "CDCA2", "CDCA5", "CDCA8", "CDK1", "CDT1", 
				"CENPE", "CENPF", "CENPK", "CENPN", "CENPS", "CENPW", "DIAPH3", "DLGAP5", "ECT2", "ESCO2", "FAM83D", "HJURP", "KIF11", "KIF14", "KIF15", "KIF18A", 
				"KIF18B", "KIF23", "KIF2C", "KIF4A", "KIFC1", "KNL1", "MAD2L1", "MKI67", "NCAPG", "NCAPH", "NDC80", "NEK2", "NUF2", "NUSAP1", "OIP5", "PLK1", "PRC1", "PSRC1", 
				"PTTG1", "RACGAP1", "SGO1", "SGO2", "SKA1", "SKA3", "SPAG5", "SPC24", "SPC25", "TACC3", "TOP2A", "TPX2", "TRIP13", "TTK", "UBE2C", "UHRF1", "ZWILCH", "ZWINT"};

// The length of the list varies from 4 to 125 items, depending on the specific report

// split the original list into n lists of equal size
col_lists = splitList_fxn( datastring, n );

// create table box and append string col boxes with each list
table = tablebox();
for each( {list,index}, col_lists,
	table << append( string col box( "Col " || char(index), list ) )
);

// create report window
rep_w = new window( "REPORT TEST", 
	
	mainframe = HList Box("DATA",
		table	
	)	
);

n = 4
scott_allen_0-1759432602375.png

n = 8

scott_allen_1-1759432846852.png

 

 

-Scott

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: JMP 17.2 > CUSTOMIZED REPORT > STRING COL BOX > How do I distribute a long list into multiple columns?

Here is one way to do what you want.  I broke the code into individual hardcoded statements assuming you will want to build some looping logic into the final code.

txnelson_1-1759431197550.png

 

 

 

theList=rep_w[stringcolbox(1)]<<get;
dtOut = New Table("Distributed");
dtOut << New Column("Dist 1" ,character);
dtOut << add rows(17);
dtOut:Dist 1 << set values(theList[index(1,17)]);
dtOut << New Column("Dist 2" ,character);
dtOut:Dist 2 << set values(theList[index(18,34)]);
dtOut << New Column("Dist 3" ,character);
dtOut:Dist 3 << set values(theList[index(35,51)]);
dtOut << New Column("Dist 4" ,character);
dtOut:Dist 4 << set values(theList[index(52,68)]);
Jim
Thierry_S
Super User

Re: JMP 17.2 > CUSTOMIZED REPORT > STRING COL BOX > How do I distribute a long list into multiple columns?

Hi txnelson,

 

Thank you for your feedback, but this provides a solution to parsing input from a String Col Box into a Table. I am actually looking for something else: how to parse a list into multiple columns within a String Col Bax structure?

 

Best,

TS

Thierry R. Sornasse
txnelson
Super User

Re: JMP 17.2 > CUSTOMIZED REPORT > STRING COL BOX > How do I distribute a long list into multiple columns?

Is this what you want

txnelson_1-1759432171402.png

Names Default to Here (1);

datastring = {	"ASPM", "AURKA", "AURKB", "BIRC5", "BUB1", "BUB1B", "CCNB1", "CCNB2", "CCNE2", "CDC20", "CDC6", "CDCA2", "CDCA5", "CDCA8", "CDK1", "CDT1", 
				"CENPE", "CENPF", "CENPK", "CENPN", "CENPS", "CENPW", "DIAPH3", "DLGAP5", "ECT2", "ESCO2", "FAM83D", "HJURP", "KIF11", "KIF14", "KIF15", "KIF18A", 
				"KIF18B", "KIF23", "KIF2C", "KIF4A", "KIFC1", "KNL1", "MAD2L1", "MKI67", "NCAPG", "NCAPH", "NDC80", "NEK2", "NUF2", "NUSAP1", "OIP5", "PLK1", "PRC1", "PSRC1", 
				"PTTG1", "RACGAP1", "SGO1", "SGO2", "SKA1", "SKA3", "SPAG5", "SPC24", "SPC25", "TACC3", "TOP2A", "TPX2", "TRIP13", "TTK", "UBE2C", "UHRF1", "ZWILCH", "ZWINT"};

// The length of the list varies from 4 to 125 items, depending on the specific report

rep_w = New Window ("REPORT TEST",
	
	mainframe = HList Box("DATA",
		
		text_data = TableBox (Col Span Box ("MEMBERS"))
		
	)
);

text_data[colspanbox(1)]<<append(string col box("Genes 1", datastring[index(1,17)]));
text_data[colspanbox(1)]<<append(string col box("Genes 2", datastring[index(18,34)]));
text_data[colspanbox(1)]<<append(string col box("Genes 3", datastring[index(35,51)]));
text_data[colspanbox(1)]<<append(string col box("Genes 4", datastring[index(52,68)]));
 

 

Jim

Re: JMP 17.2 > CUSTOMIZED REPORT > STRING COL BOX > How do I distribute a long list into multiple columns?

@Thierry_S 

Here is a generalized way to do it in JSL. I created a function the requires an original list and an integer. The function splits the original list into n number of smaller lists and returns the list of lists. In the case that the number of items in the original list is not evenly divisible by n, the nth column will have the balance of items. This keeps the function general in case you want to use it again for a table with more or less columns. 

The table is then created by appending each list as a string col box to a table box:

Names Default to Here (1);

splitList_fxn = function( {list, n}, 

	// split a list into into n evenly divided lists and return a list of lists
	// if list items/n is not an integer, place the extra items in the nth column

	{i,j,k,n,lists,thisList,listSize,items},
	
	lists = {};
	items = n items( list );
	listSize = round( items/n );
	
	k = 0; // counter
	for( i = 1, i <= n, i++,
		thisList = {};
		if( i != n,
		
			// all but the last list
			for( j = (k*listSize)+1, j <= listSize*i, j++, 
				insert into( thisList, list[j] )
			),
			
			// last list will be the remaining items in case there is a remainder
			for( j = (k*listSize)+1, j <= items, j++,
				insert into( thisList, list[j] )
			)
		);
		k++;
		insert into( lists, eval list( list( thisList ) ) )
	);
	return( lists )
);

// number of columns
n = 4;

// original list
datastring = {	"ASPM", "AURKA", "AURKB", "BIRC5", "BUB1", "BUB1B", "CCNB1", "CCNB2", "CCNE2", "CDC20", "CDC6", "CDCA2", "CDCA5", "CDCA8", "CDK1", "CDT1", 
				"CENPE", "CENPF", "CENPK", "CENPN", "CENPS", "CENPW", "DIAPH3", "DLGAP5", "ECT2", "ESCO2", "FAM83D", "HJURP", "KIF11", "KIF14", "KIF15", "KIF18A", 
				"KIF18B", "KIF23", "KIF2C", "KIF4A", "KIFC1", "KNL1", "MAD2L1", "MKI67", "NCAPG", "NCAPH", "NDC80", "NEK2", "NUF2", "NUSAP1", "OIP5", "PLK1", "PRC1", "PSRC1", 
				"PTTG1", "RACGAP1", "SGO1", "SGO2", "SKA1", "SKA3", "SPAG5", "SPC24", "SPC25", "TACC3", "TOP2A", "TPX2", "TRIP13", "TTK", "UBE2C", "UHRF1", "ZWILCH", "ZWINT"};

// The length of the list varies from 4 to 125 items, depending on the specific report

// split the original list into n lists of equal size
col_lists = splitList_fxn( datastring, n );

// create table box and append string col boxes with each list
table = tablebox();
for each( {list,index}, col_lists,
	table << append( string col box( "Col " || char(index), list ) )
);

// create report window
rep_w = new window( "REPORT TEST", 
	
	mainframe = HList Box("DATA",
		table	
	)	
);

n = 4
scott_allen_0-1759432602375.png

n = 8

scott_allen_1-1759432846852.png

 

 

-Scott
hogi
Level XIII

Re: JMP 17.2 > CUSTOMIZED REPORT > STRING COL BOX > How do I distribute a long list into multiple columns?

splitList_fxn = function( {list, n}, 
	{default local},
	lists = {};
	
	Nparts =ceiling(nitems(list)/n);
	i=0;
	
	while(nitems(list),
	i++;
	chunk = remove from (list, 1,Nparts);
	Insert Into(lists, eval list({chunk}));
	);
	
	if(i<n,
		print("n lists: " || char(i))
	);
	
	return( lists )
);


splitList_fxn(datastring,15)


Insert Into(lists, eval list({chunk}));  ?
It's need till:
Insert Into: Flatten(0|1) 

Recommended Articles