cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
newbie_alex
Level III

how to convert column names to a list of strings

Hi,

 

I would like to convert column names to strings but I do not know how.

 

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

col_names = dt << Get Column Names();

Show(col_names);

this leads to

col_names = {Name, Country, Score, Name("100m"), Long Jump, Shot Put, High Jump, Name("400m"), Name("100m hurdles"), Discus, Pole Vault, Javelin, Name("1500m")};

I would like to have something like this instead:

col_names = {"Name", "Country", "Score", "100m", "Long Jump", "Shot Put", "High Jump", "400m", "100m hurdles", "Discus", "Pole Vault", "Javelin", "1500m"};

Any idea?

 

Thank you for your help!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Staff

Re: how to convert column names to a list of strings

Try '<< getColumnNames("String")'.

 

Look out for the editor tooltips that pop up for coloured keywords, or use 'Help > Scripting Index' to dig deeper.

View solution in original post

20 REPLIES 20
ian_jmp
Staff

Re: how to convert column names to a list of strings

Try '<< getColumnNames("String")'.

 

Look out for the editor tooltips that pop up for coloured keywords, or use 'Help > Scripting Index' to dig deeper.

newbie_alex
Level III

Re: how to convert column names to a list of strings

Thank you!

newbie_alex
Level III

Re: how to convert column names to a list of strings

Is there something similar for Get Variables() ?

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = Graph Builder( Variables( X( :height ), Y( :weight ) ), Elements( Points( X, Y ), Smoother( X, Y ) ) );
gbb = Report( gb )[Graph Builder Box( 1 )];
gbb << Get Variables();
mela_ssa
Level III

Re: how to convert column names to a list of strings

Try adding String as the argument of the Get Column Names function.
For example:

col_str = dt << Get Column Names(String);
It results in
{"Name", "Country", "Score", "100m", "Long Jump", "Shot Put", "High Jump", "400m",
"100m hurdles", "Discus", "Pole Vault", "Javelin", "1500m"}
mela_ssa
Level III

Re: how to convert column names to a list of strings

 

Try adding String in the Get Column Names function. For example:

col_str = dt << Get Column Names(String);
It results in

 

{"Name", "Country", "Score", "100m", "Long Jump", "Shot Put", "High Jump", "400m",
"100m hurdles", "Discus", "Pole Vault", "Javelin", "1500m"}

txnelson
Super User

Re: how to convert column names to a list of strings

If you are looking to get what variables were used Post Hoc to the platform being run, you can always extract the script used for produce the platform, and to examine it to get the variables

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
obj = Graph Builder(
	Variables(
		X( :Sex ),
		Y( :Height ),
		Group X( :Age )
	),
	Elements( Box Plot( X, Y ) )
);
t = obj << Get Script;
Show( t );
Jim
newbie_alex
Level III

Re: how to convert column names to a list of strings

Thank you for the feedback.

 

The idea is to use JSL to do something with the list of graph variables (e.g. check what color was assigned by graph builder for a given variable (which do not know how to do yet)) and use the result to do something else (e.g. make sure that the same color is used in another graph).

 

Parsing the whole graph builder script returned by Get Script to determine the list of variable names seems to be a fairly complicated way of doing this.

 

txnelson
Super User

Re: how to convert column names to a list of strings

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = Graph Builder( Variables( X( :height ), Y( :weight ) ), Elements( Points( X, Y ), Smoother( X, Y ) ) );
// you could extract the x and y labels if you think
// these might have remained as the variable names
yvar=report(gb)[TextEditBox(3)]<<get text;
xvar=report(gb)[TextEditBox(2)]<<get text;
Jim
ian_jmp
Staff

Re: how to convert column names to a list of strings

Following Jim's thinking, maybe something like?

Names Default To Here( 1 );
// Make a Graph Builder report
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = Graph Builder( Variables( X( :height ), Y( :weight ) ), Elements( Points( X, Y ), Smoother( X, Y ) ) );
// Post-hoc interrogation of the report . . .
// (1) Get the script that launched the platform (or do: ' sc = gb << getScript')
sc = (Report(gb) << getScriptableObject) << getScript;
// (2) Pick apart the script expression and get what's needed
varList = {};
for(i=1, i<=Narg(Arg(sc,1)), i++,
	InsertInto(varList, Arg(Arg(Arg(sc,1), i),1));
);
Print(varList);

The code is a little terse, but you can use 'Help > Scripting Guide' to see what at 'Arg()' and 'NArg()' do.