cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
timothy_forsyth
Level III

How to unstack a JMP table with a many to one structure

Hi,

 

I have the following "stacked" data table in JMP;

 

Test IDSample TypeResult
Test_ID_1Sample 10
Test_ID_1Sample 12
Test_ID_1Sample 11
Test_ID_1Sample 14
Test_ID_1Sample 9
Test_ID_1Control11
Test_ID_2Sample 9
Test_ID_2Sample 8
Test_ID_2Sample 10
Test_ID_2Control14
Test_ID_3Sample 13
Test_ID_3Control15
Test_ID_4Sample 9
Test_ID_4Sample 7
Test_ID_4Control12

 

 

I would like to generate the following table from the above table by unstacking;

 

 

Test IDSample Type = SampleSample Type = Control
Test_ID_11011
Test_ID_11211
Test_ID_11111
Test_ID_11411
Test_ID_1911
Test_ID_2914
Test_ID_2814
Test_ID_21014
Test_ID_31315
Test_ID_4912
Test_ID_4712

 

The stacked data contains a varied number of samples for a given control.  Sometimes there is a 1-to-1 correlation between sample and control but more often there is a many samples to one control. The number of samples can vary from one to n but there is always just one control.  I am using JMP 16.0.1.

 

Thanks,

 

Tim

Drink deep, or taste not the Pierian spring
2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: How to unstack a JMP table with a many to one structure

Here is a little script that converts your simple example table into the new format you want.  It uses a couple of subsets along with an Update to accomplish the task.

Names Default To Here( 1 );
dt = Current Data Table();
dt << select where( :Sample Type == "Sample" );
dtFinal = dt << subset(
	selected rows( 1 ),
	columns( {"Test ID", "Result"} ),
	Output Table( "Final" )
);
dtFinal:Result << set name( "Sample Type = Sample" );
dt << invert row selection;
dtTemp = dt << subset( invisible,
	selected rows( 1 ),
	columns( {"Test ID", "Result"} )
);
dtTemp:Result << set name( "Sample Type = Control" );
dtFinal <<Update(
	With( dtTemp ),
	Match Columns( :Test ID = :Test ID )
);

close( dtTemp, nosave );

txnelson_0-1669341369151.png

 

Jim

View solution in original post

jthi
Super User

Re: How to unstack a JMP table with a many to one structure

You can also try to create grouping column

Col Cumulative Sum(1, :Test ID, :Sample Type)

jthi_0-1669361444208.png

Use that with Split

jthi_1-1669361476446.png

jthi_2-1669361485726.png

And then select one row from control colum and fill with previous value

jthi_3-1669361523548.png

and cleanup (remove order column, re-order columns, rename if needed)

jthi_4-1669361565167.png

 

This works in this fairly simple case, but it is also fairly easy to loose data when using JMP's split platform so be careful with (order column tries to prevent this).

-Jarmo

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: How to unstack a JMP table with a many to one structure

Here is a little script that converts your simple example table into the new format you want.  It uses a couple of subsets along with an Update to accomplish the task.

Names Default To Here( 1 );
dt = Current Data Table();
dt << select where( :Sample Type == "Sample" );
dtFinal = dt << subset(
	selected rows( 1 ),
	columns( {"Test ID", "Result"} ),
	Output Table( "Final" )
);
dtFinal:Result << set name( "Sample Type = Sample" );
dt << invert row selection;
dtTemp = dt << subset( invisible,
	selected rows( 1 ),
	columns( {"Test ID", "Result"} )
);
dtTemp:Result << set name( "Sample Type = Control" );
dtFinal <<Update(
	With( dtTemp ),
	Match Columns( :Test ID = :Test ID )
);

close( dtTemp, nosave );

txnelson_0-1669341369151.png

 

Jim
jthi
Super User

Re: How to unstack a JMP table with a many to one structure

You can also try to create grouping column

Col Cumulative Sum(1, :Test ID, :Sample Type)

jthi_0-1669361444208.png

Use that with Split

jthi_1-1669361476446.png

jthi_2-1669361485726.png

And then select one row from control colum and fill with previous value

jthi_3-1669361523548.png

and cleanup (remove order column, re-order columns, rename if needed)

jthi_4-1669361565167.png

 

This works in this fairly simple case, but it is also fairly easy to loose data when using JMP's split platform so be careful with (order column tries to prevent this).

-Jarmo