cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

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

Stacking multiple columns, and adding repeating values to new columns

Hello folks

I have a original set of data with first row as sample/location, and next rows shows values corresponding to specific iterations.

EdgeMarmoset719_1-1744915552905.png

 

I'd like to change this data, stacking the values and creating the new column showing Sample/Location separately. 

This is what I'd like to have: repeating iteration/sample/location for each values. 

EdgeMarmoset719_2-1744915743465.png

 

Alternatively, I'd like to have this; if separating the Sample/Location is difficult: 

EdgeMarmoset719_3-1744915817399.png

 

I' tried to find a way with summary table from UI, but nothing seems to be working.

 

Attaching the excel data file.

 

3 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Stacking multiple columns, and adding repeating values to new columns

Stack your data

jthi_0-1744916490397.png

Use First Word (and Last Word) quick formulas with slight modifications to create new columns

jthi_1-1744916531687.png

Modify Last Word to use "-" instead of default value which is " "

jthi_2-1744916578594.png

You can also add trim whitespace to clean the last word a bit

Trim Whitespace(Word(-1, :Label, "-"))

jthi_3-1744916615006.png

 

Is this what you are looking for? (also for the future, I would suggest sharing your data as JMP tables to avoid all sorts of issues excel files can potentially create)

-Jarmo

View solution in original post

jthi
Super User

Re: Stacking multiple columns, and adding repeating values to new columns

And for modifying the data, you can also take a look at Recode platform (  Using JMP > Enter and Edit Your Data > Restructure Data > Recode Data in a Column ). And in some cases you can also just use Text to Columns

jthi_0-1744918086975.png

and of course you can combine it with Recode if necessary. JMP is also able to write script for you for this whole process either as a workflow or as a script in enhanced log

-Jarmo

View solution in original post

hogi
Level XIII

Re: Stacking multiple columns, and adding repeating values to new columns

prepare some data:

//prepare: 
Names Default to Here(1);
dt0 = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt = dt0 << Split(
	Split By( :age, :sex ),
	Split( :height ),
	Remaining Columns( Drop All )
);
dt << new column ("sample", set each value(row()));

 

Now, let's stack it:

hogi_0-1744918073692.png

 

- use Eliminate missing rows( 1 ) to get rid of empty entries

- use text to column to split the 2 grouping variables:

hogi_1-1744918215977.png

 

if you prefer JSL:

// create stacked table
stacked = dt  <<
Stack(
	columns(
		:"12 F"n, :"12 M"n, :"13 F"n, :"13 M"n, :"14 F"n, :"14 M"n, :"15 F"n,
		:"15 M"n, :"16 F"n, :"16 M"n, :"17 F"n, :"17 M"n
	),
	Stack By Row( 0 ),
	Eliminate missing rows( 1 )
);
stacked << Text to Columns( columns( :Label ), Delimiters( " " ) );

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Stacking multiple columns, and adding repeating values to new columns

Stack your data

jthi_0-1744916490397.png

Use First Word (and Last Word) quick formulas with slight modifications to create new columns

jthi_1-1744916531687.png

Modify Last Word to use "-" instead of default value which is " "

jthi_2-1744916578594.png

You can also add trim whitespace to clean the last word a bit

Trim Whitespace(Word(-1, :Label, "-"))

jthi_3-1744916615006.png

 

Is this what you are looking for? (also for the future, I would suggest sharing your data as JMP tables to avoid all sorts of issues excel files can potentially create)

-Jarmo
jthi
Super User

Re: Stacking multiple columns, and adding repeating values to new columns

And for modifying the data, you can also take a look at Recode platform (  Using JMP > Enter and Edit Your Data > Restructure Data > Recode Data in a Column ). And in some cases you can also just use Text to Columns

jthi_0-1744918086975.png

and of course you can combine it with Recode if necessary. JMP is also able to write script for you for this whole process either as a workflow or as a script in enhanced log

-Jarmo
hogi
Level XIII

Re: Stacking multiple columns, and adding repeating values to new columns

prepare some data:

//prepare: 
Names Default to Here(1);
dt0 = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt = dt0 << Split(
	Split By( :age, :sex ),
	Split( :height ),
	Remaining Columns( Drop All )
);
dt << new column ("sample", set each value(row()));

 

Now, let's stack it:

hogi_0-1744918073692.png

 

- use Eliminate missing rows( 1 ) to get rid of empty entries

- use text to column to split the 2 grouping variables:

hogi_1-1744918215977.png

 

if you prefer JSL:

// create stacked table
stacked = dt  <<
Stack(
	columns(
		:"12 F"n, :"12 M"n, :"13 F"n, :"13 M"n, :"14 F"n, :"14 M"n, :"15 F"n,
		:"15 M"n, :"16 F"n, :"16 M"n, :"17 F"n, :"17 M"n
	),
	Stack By Row( 0 ),
	Eliminate missing rows( 1 )
);
stacked << Text to Columns( columns( :Label ), Delimiters( " " ) );

Recommended Articles