how to convert column names to a list of stringsHi,
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!
Re: how to convert column names to a list of stringsthe below will assign a string value of a columns name, for the first selected column in the current active data table.
dt = current data table();
theName = ((dt<<GET selected="" columns=""></GET>
Re: how to convert column names to a list of stringssuppose I have a single column name as a variable, how would I make that column name into a string? E.g. a user dialog selects a column, I want that column name as a string. Thanks.
Re: how to convert column names to a list of stringsThis worked but I needed to first make a group name variable.
j=1;
GN = "ColGroup"||j;
dt << Group Columns(GN, col_list);
worked.
But
dt << Group Columns("ColGroup"||j, col_list);
did not.
It turned out this was the problem all along.
The error message made the problem look like it was with the column list.
Re: how to convert column names to a list of stringsThis works:
dt = current data table();
col_list = {"Column 1", "Column 2", "Column 3"};
dt << Group Columns("ColGroup", col_list);Re: how to convert column names to a list of stringsI have the opposite problem. I need to convert a string list to a column name list.
I have a list of column names as strings, {"col1", "col2", "col3"}
I want to group those columns but that function needs the list to look like this:
dt << Group Columns("ColGroup", {:col1, :col2, :col3});
I've tried many permutations of eval, evapexpr and column but have not found the correct one.
Re: how to convert column names to a list of stringsSince your stated purpose is to have the same colors from Graph Builder apply to other graphs, could you use the Column Properties - Value Colors to accomplish what you want?
Re: how to convert column names to a list of stringscol_str = dt << Get Column Names( "String" ); works in JMP 13.
For JMP 12, use col_str = dt << Get Column Names( "String" );
As Ian suggested.
Re: how to convert column names to a list of stringsIt's possible the expression for the Graph Builder saved script has changed, and if so, the way the script is parsed would need to be changed accordingly. I don't have that version installed so can't easily check.
But you should be able to use the general appoach.
Re: how to convert column names to a list of stringsThanks you for the quick feedback.
I use JMP Pro 12.2.0. That might be the reason why our results differRe: how to convert column names to a list of stringsI had some issues with the Community software, and you may have got an incomplete version. At any rate, the code there now gives me (JMP Pro 13.1 on a Mac):
{:height, :weight}
Re: how to convert column names to a list of stringsThank you for your answer.
Unfortunately your code returns
{Empty()}Re: how to convert column names to a list of stringsFollowing 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.
Re: how to convert column names to a list of stringsNames 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=""></GET>
Re: how to convert column names to a list of stringsThank 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.
Re: how to convert column names to a list of stringsIf 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 );
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"}
Re: how to convert column names to a list of stringsTry 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"}Re: how to convert column names to a list of stringsIs 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();
Re: how to convert column names to a list of stringsThank you!
Re: how to convert column names to a list of stringsTry '<< getColumnNames("String")'.
Look out for the editor tooltips that pop up for coloured keywords, or use 'Help > Scripting Index' to dig deeper.