cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
simon_2
Level III

Transpose column, make transposed rows headers in JMP12

Does anyone know how to transform a column (just one column) and make the rows become the table header using JSL?

 

I am using JMP12.

Basically, I want the first row to be the column headers and not the output below. My dataset is attached.

 

simon_2_0-1616184507157.png

 

 

Thanks,

Simon

dt = Data Table( "sports" ) << Transpose(
			columns( :Items ),
			Output Table( "transposed" )
			);
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Transpose column, make transposed rows headers in JMP12

Hi, I don't have JMP 12 loaded anymore but I think all of what I used here was around in JMP 12... give this a go.

 

Cheers,

Brady

 

p.s.--we've added a lot of cool stuff since JMP 12 !!

 

Names Default To Here(1);

//replicate your original table
dt = New Table( "sports",
	New Column( "Items", Character,	"Nominal",
		Set Values( {"soccer", "volleyball", "7tennis", "basketball"} ),
	)
);


//get a list of desired column names.
colNameList = dt:items << get values; 

/*
If you're creating a new table: build a 1 row, n column matrix of missing data
with the J() function and the As Table() function, which lets you set column names
easily.
*/
newDt = as table (J (1, nitems(colNameList), .), <<column names( colNameList));


//if you're overwriting onto your present table:
for (i=1, i<=nitems(colNameList), i++,
	try(
		column(dt, i) << set name(colNameList[i]) //try to change ith column name
	,
		dt << new column (colNameList[i]) // if no ith column exists, create one
	)
);

 

 

View solution in original post

4 REPLIES 4

Re: Transpose column, make transposed rows headers in JMP12

Hi, I don't have JMP 12 loaded anymore but I think all of what I used here was around in JMP 12... give this a go.

 

Cheers,

Brady

 

p.s.--we've added a lot of cool stuff since JMP 12 !!

 

Names Default To Here(1);

//replicate your original table
dt = New Table( "sports",
	New Column( "Items", Character,	"Nominal",
		Set Values( {"soccer", "volleyball", "7tennis", "basketball"} ),
	)
);


//get a list of desired column names.
colNameList = dt:items << get values; 

/*
If you're creating a new table: build a 1 row, n column matrix of missing data
with the J() function and the As Table() function, which lets you set column names
easily.
*/
newDt = as table (J (1, nitems(colNameList), .), <<column names( colNameList));


//if you're overwriting onto your present table:
for (i=1, i<=nitems(colNameList), i++,
	try(
		column(dt, i) << set name(colNameList[i]) //try to change ith column name
	,
		dt << new column (colNameList[i]) // if no ith column exists, create one
	)
);

 

 

simon_2
Level III

Re: Transpose column, make transposed rows headers in JMP12

works like a charm.

 

Thanks a lot!

txnelson
Super User

Re: Transpose column, make transposed rows headers in JMP12

@brady_brady probably provided you with better solutions, but if all you want to do, is to create an empty data table where the column names are the value from the first row, the following will do a real simple job of that

header1.PNG

dtNew = Data Table( "sports" ) << Split(
	Split By( :Items ),
	Split( Transform Column( "Transform[Items]", Nominal, Formula( . ) ) ),
	Sort by Column Property
);
dtNew << delete rows(1);

 

Jim
simon_2
Level III

Re: Transpose column, make transposed rows headers in JMP12

Thanks @txnelson