cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
razmah
Level II

How to select a column with specific name?

Hi

Assume I have a table with columns 1-10.

then I have a 3 variables. for example A=2, B=7, C=10

I want to write a script to select columns with amounts of A, B, and C and plot it vs col.1.

here it should select columns of 2, 7, and 10 and use overlay plot to plot it vs column1.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Eric_Hill
Staff

Re: How to select a column with specific name?

Selecting columns by name is easy enough:

dt = Current Data Table();

a = 2;

b = 7;

c = 9;

Column( dt, Char( a ) ) << Set Selected;

Column( dt, Char( b ) ) << Set Selected;

Column( dt, Char( c ) ) << Set Selected;

But I'm not sure you need to select them to create the overlay plot you are looking for.  You can just do this:

Overlay Plot( X( :Name( "1" ) ), Y( Column( dt, Char(a) ), Column( dt, Char(b) ),

   Column( dt, Char(c) ) ) );

If you have a variable number of Y variables, you can construct a list of them and set that list as the Y variables for overlay plot:

colList = {};

colList = Insert( colList, Column( dt, Char( a ) ) );

colList = Insert( colList, Column( dt, Char( b ) ) );

colList = Insert( colList, Column( dt, Char( c ) ) );

Overlay Plot( X( :Name( "1" ) ), Y( EvalList(colList) ) );

HTH,

Eric

View solution in original post

3 REPLIES 3
Eric_Hill
Staff

Re: How to select a column with specific name?

Selecting columns by name is easy enough:

dt = Current Data Table();

a = 2;

b = 7;

c = 9;

Column( dt, Char( a ) ) << Set Selected;

Column( dt, Char( b ) ) << Set Selected;

Column( dt, Char( c ) ) << Set Selected;

But I'm not sure you need to select them to create the overlay plot you are looking for.  You can just do this:

Overlay Plot( X( :Name( "1" ) ), Y( Column( dt, Char(a) ), Column( dt, Char(b) ),

   Column( dt, Char(c) ) ) );

If you have a variable number of Y variables, you can construct a list of them and set that list as the Y variables for overlay plot:

colList = {};

colList = Insert( colList, Column( dt, Char( a ) ) );

colList = Insert( colList, Column( dt, Char( b ) ) );

colList = Insert( colList, Column( dt, Char( c ) ) );

Overlay Plot( X( :Name( "1" ) ), Y( EvalList(colList) ) );

HTH,

Eric

pmroz
Super User

Re: How to select a column with specific name?

If you want to use column 1 as x, and columns 2, 7, and 10 as Y, regardless of their names, then this will do the trick:

dt = current data table();

xc = 1;    // column 1

a = 2;     // column 2

b = 7;     // column 7

c = 9;     // column 9

overlay plot(x(column(xc)), y(column(a), column(b), column(c)));

razmah
Level II

Re: How to select a column with specific name?

Hi Eric,

I have another question looks like last one:

columns a, b, c are variables; how can I add new column and give it a formula by use of a,b, and c?

I wrote following script but column doesn't show the formula.

New Column( "a /b",Numeric,Continuous,Format( "Best", 12 ),

Formula( :column(char(a)) /  :column( char(b)) ));

thank you for your recommendation