cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
novicepg
Level I

Rename column name based on value from xth rows

Hi All,

I am trying to use jsl to rename the column name of a datatable using rows value from row that met predefined criteria.

My script is as followed:

  dt = Open();
  Current Data Table() << set name( "ABC" );
  dt = Data Table( "ABC" );
  lastcol = N Col( dt );
  header=dt<<Get Rows Where (:(2)=="Colour"); // this is the criteria, i wanted to identify the row where the value in column2 is "Colour"
  For( i = 2, i <= lastcol, i++,
   Column( i ) << set Name( Column( i )[header] )
  );

unfortunately this method doesnt work. Can anyone please guide or share me what's wrong with the script and how can i achieve what i want? Thanks a lot!

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Rename column name based on value from xth rows

<<Get rows where() returns a matrix. If there is only one instance of "Colour" the matrix will have a single number. You need to extract that number of the matrix header before using it as an index.

Here are two examples that both should work.

header=(dt<<Get Rows Where(:(2)=="Colour"))[1]; // header is a number

  For( i = 2, i <= lastcol, i++,

   Column( i ) << set Name( Column(i)[header] )

  );

 

  header=dt<<Get Rows Where(:(2)=="Colour"); // header is a 1x1 matrix

  For( i = 2, i <= lastcol, i++,

   Column( i ) << set Name( Column(i)[header[1]] ) // exctract the (first) number of the matrix header

  );

View solution in original post

2 REPLIES 2
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Rename column name based on value from xth rows

<<Get rows where() returns a matrix. If there is only one instance of "Colour" the matrix will have a single number. You need to extract that number of the matrix header before using it as an index.

Here are two examples that both should work.

header=(dt<<Get Rows Where(:(2)=="Colour"))[1]; // header is a number

  For( i = 2, i <= lastcol, i++,

   Column( i ) << set Name( Column(i)[header] )

  );

 

  header=dt<<Get Rows Where(:(2)=="Colour"); // header is a 1x1 matrix

  For( i = 2, i <= lastcol, i++,

   Column( i ) << set Name( Column(i)[header[1]] ) // exctract the (first) number of the matrix header

  );

novicepg
Level I

Re: Rename column name based on value from xth rows

Thank you MS! This works!

By the way, how do i mark this as "solved" or "answered"?