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

Renaming Columns

Hi everyone,

 

In my code, I open up a csv file, and I rename the column to "Column 1".  In the data table, it is renamed, but when I search through all the different columns, it can't find "Column 1". It only recognizes its original name when it is opened.  I am searching for values with in a data table, and I need to know what column it is in (which is working if I set i to 2).  I know that setting i to 2 would work for this application, but in general, I think it would be good to know why this is happening.

colFunction = Function({search_string},
  found =0;
  i=1;
  Show(search_string);
  Show(nCols);
  While (found == 0,
 
  match_rows = dt << get rows where(as column(dt, nCols)==search_string);
  if(nrows(match_rows) > 0, found = 1, i++);
  if(i==nCols, found =1, );
  );
  col = Num(i);
);
 
file = Pick File();
dt = Open (file);
 
 
for(i=1, i<=ncols(dt), i++,
 
  column(dt,i) << data type(Character);
  column(dt,i) << set modeling type(continuous);
);
 
 
nCols = dt << Get Column Names ("Character");
col = Column (1);
col << set name("Column 1");
 
irglCol = colFunction("Irgl");

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

Re: Renaming Columns

@txnelson showed you the scripting solution, but this is pretty easy to deal with interactively too.

 

You can copy the column names from the list on the left side of the data table and then paste them into a column of a new data table. Now you've got access to all the capabilitles of the formula editor to manipulate them.

 

Then copy them from the new column and paste them back into the original table.

 

Here's a little video showing the technique.

 

-Jeff

View solution in original post

5 REPLIES 5
Byron_JMP
Staff

Re: Renaming Columns

get column names gets just the list of column names

get column references gets the names as strings

 

so maybe a couple of other ideas too.

 

open(); //dont have to pick the file, it automatically opens the pic file dialogue

 

Get the column list, find the position of the pattern and then change the column name using the position at the reference

 

 

list=dt<< get column reference();  //gets strings not a list of columns
position=contains(list, column("Carline"));    //finds the position of something in a list
 
column(position)<<setname("Caroline");

or I guess you could get really crazy and substitute in the list and rename all the columns with the list

newlist=substitute(list, string, "Column 1");
dt<<set column names(newlist);

 

JMP Systems Engineer, Health and Life Sciences (Pharma)
syedhashmi
Level II

Re: Renaming Columns

Hi All,

              I have a similar issue, but not exactly the same: I have a JMP table with 100's of columns and majority of those column names start with the number 0 which makes it hard to go/search for a specific column. is there a way I can remove the number 0 at the beginning of each column through a JMP script.

If it was one or two columns, I could have done it manually but these are in 100's...I know how to change name for one column at a time, but in this case I think i need to somehow use a loop or something...

please let me know if there are some ways this can be achieved.

appreciate all the help.

thanks.

txnelson
Super User

Re: Renaming Columns

Here is a simple script that will do what you need

Names Default To Here( 1 );
dt = Current Data Table();
ColList = dt << get column names( string );

For( i = 1, i <= N Items( ColList ), i++,
	If( Substr( ColList[i], 1, 1 ) == "0",
		Column( dt, i ) << set name( Substr( ColList[i], 2 ) )
	)
);
Jim
Jeff_Perkinson
Community Manager Community Manager

Re: Renaming Columns

@txnelson showed you the scripting solution, but this is pretty easy to deal with interactively too.

 

You can copy the column names from the list on the left side of the data table and then paste them into a column of a new data table. Now you've got access to all the capabilitles of the formula editor to manipulate them.

 

Then copy them from the new column and paste them back into the original table.

 

Here's a little video showing the technique.

 

-Jeff
syedhashmi
Level II

Re: Renaming Columns

totally awesome..works like a charm. 

 

thanks a lot.