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

Transpose non specific data columns

Hi all,

I am creating a script in jsl but I am having a problem in transposing the table since the columns needed needs to be specified. However, in my case, the columns depend on the data, so it is changing. 

 

How can I create a jsl script where I can transpose non specific data columns?

2 REPLIES 2
jthi
Super User

Re: Transpose non specific data columns

When you know the names of columns you wish to transpose, you can use them in Transpose(columns()) using eval

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

cols_to_transpose = {"height", "weight"};

dt_transposed = dt << Transpose(
	columns(Eval(cols_to_transpose)),
	Label column name("name"),
	Output Table("Transpose of Big Class")
);
-Jarmo
txnelson
Super User

Re: Transpose non specific data columns

Here is one example of a Transpose script that  examines the data from the data table and generates a transposed data table based upon the data;

Names Default To Here( 1 );

theTranspose = Expr(
	dt = Current Data Table();

// Get the first character column to use as the Label
	theLabel = (dt << get column names( string, character ))[1];

// Get the numeric columns.  All numeric columns will be transposed
	theTransColumns = dt << get column names( string, numeric );

// Transpose the data
	dt << Transpose( columns( theTransColumns ), Label( As Column( theLabel ) ) );
);

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

theTranspose;

// Open Data Table: Blood Pressure.jmp
// → Data Table( "Blood Pressure" )
Open( "$SAMPLE_DATA/Cities.jmp" );

theTranspose;

I am sure this does not solve your specific problem, however, not knowing what your rules for how you want to transpose were not specified, I set the rules to be that all numeric columns found will be transposed, and that the first character column found would contain the new column names.

Jim