Subscribe Bookmark RSS Feed

Script to transpose data in an existing data table

mkennke

Community Trekker

Joined:

Mar 18, 2016

Hi,

I like to find a script to transpose data. And this data should be inserted at the last row of an existing file. Following how I transpose the data:

 

Data Table( "pisnapshot Abfrage AL2" ) << Transpose(

       columns( :value ),

       Transpose selected rows only( 1 ),

       Output Table( "AL2 Snapshot Transpose" )

);

Data Table( "pisnapshot Abfrage AL2" )

 

With that JMP copies the data every time a new Data Table. How is it possible to copy it into an existing File (File is open)?

I got the idea to select the transposed row ("AL2 Snapshot Transpose") and to copy it into my target file. But I was not able to find a command to copy the Row Values.

1 ACCEPTED SOLUTION

Accepted Solutions
mkennke

Community Trekker

Joined:

Mar 18, 2016

Solution

Thank you for the fast response.

 

Meanwhile I tried something different. Therefore I used the function “concentrate”:

//transponse table
Data Table( "pisnapshot Abfrage AL2" ) << Transpose(
	columns( :value ),
	Transpose selected rows only( 1 ),
	Label( :tag ),
	Output Table( "AL2 Snapshot Transpose" ));

//add Table "AL2 Snapshot Transpose" to exsiting table "AL2 Snapshot"
Data Table( "AL2 Snapshot" ) << Concatenate(Data Table( "AL2 Snapshot Transpose" ),Append to first table);
//close table with “no save”
Close(Data Table( "AL2 Snapshot Transpose" ), No Save);

 

And it works perfectly. But I will try your solution .

3 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

I think the script below is a simplier solution to what you stated you want

Names Default To Here( 1 );
dt = Current Data Table();

// Get the selected rows
selRows = dt << get selected rows;

If( N Rows( selRows ) > 0, 
// Add the row to place the data into
	dt << Add Rows( 1 );

// Go from column to column and move the selected data to the new row
	For( i = 1, i <= N Cols( dt ), i++,
		Column( dt, i )[N Rows( dt )] = Column( dt, N Col( dt ) )[selRows[i]]
	);

// Delete the last column
	dt << delete columns( Column( dt, N Cols( dt ) ) );
);
Jim
mkennke

Community Trekker

Joined:

Mar 18, 2016

Solution

Thank you for the fast response.

 

Meanwhile I tried something different. Therefore I used the function “concentrate”:

//transponse table
Data Table( "pisnapshot Abfrage AL2" ) << Transpose(
	columns( :value ),
	Transpose selected rows only( 1 ),
	Label( :tag ),
	Output Table( "AL2 Snapshot Transpose" ));

//add Table "AL2 Snapshot Transpose" to exsiting table "AL2 Snapshot"
Data Table( "AL2 Snapshot" ) << Concatenate(Data Table( "AL2 Snapshot Transpose" ),Append to first table);
//close table with “no save”
Close(Data Table( "AL2 Snapshot Transpose" ), No Save);

 

And it works perfectly. But I will try your solution .

txnelson

Super User

Joined:

Jun 22, 2012

yours is a better solution if you have the ":Tag" column for the matching of column names
Jim