Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
Level V

## Move Selected Columns() with list parameter

If I have a table with five columns:

 Column 5 Column 3 Column 2 Column 1 Column 4 data data data data data

and I execute this:

``````dt = Current Data Table();
dt << Move Selected Columns({"Column 1", "Column 2", "Column 3", "Column 4", "Column 5"}, To first)``````

then I get this:

 Column 1 Column 2 Column 3 Column 4 Column 5 data data data data data

But if I execute this:

``````dt= Current Data Table();
list = {"Column 1", "Column 2", "Column 3", "Column 4", "Column 5"};
dt << Move Selected Columns( list, To first); ``````

it fails with an "Unrecognized key word" error.

I need to be able to parameterize the column list, as in the second version. How can I make something like the second version work?

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Super User

## Re: Move Selected Columns() with list parameter

I tried various flavors of as list(), listeval(), expr, evalexpr(), etc. to no avail.  Had to resort to eval(parse()):

``````dt = current data table();

alist = {"Column 4", "Column 3", "Column 2", "Column 1"};
clist = char(alist);

col_expr = evalinsert("dt << move selected columns(^clist^, to first)");

eval(parse(col_expr));``````
Highlighted
Super User

## Re: Move Selected Columns() with list parameter

This is just an alternate method, and FYI.

You can also do this with expressions.  Eval Expr() replaces each Expr() with its value (name expression), and the external Eval() function, executes the command.

``````dt= Current Data Table();
list = {"Column 1", "Column 2", "Column 3", "Column 4", "Column 5"};
Eval( Eval Expr(dt << Move Selected Columns( Expr(list), To first)) ); ``````
4 REPLIES 4
Highlighted
Super User

## Re: Move Selected Columns() with list parameter

I tried various flavors of as list(), listeval(), expr, evalexpr(), etc. to no avail.  Had to resort to eval(parse()):

``````dt = current data table();

alist = {"Column 4", "Column 3", "Column 2", "Column 1"};
clist = char(alist);

col_expr = evalinsert("dt << move selected columns(^clist^, to first)");

eval(parse(col_expr));``````
Highlighted
Level V

## Re: Move Selected Columns() with list parameter

Thanks, that works for me!
Highlighted
Super User

## Re: Move Selected Columns() with list parameter

This is just an alternate method, and FYI.

You can also do this with expressions.  Eval Expr() replaces each Expr() with its value (name expression), and the external Eval() function, executes the command.

``````dt= Current Data Table();
list = {"Column 1", "Column 2", "Column 3", "Column 4", "Column 5"};
Eval( Eval Expr(dt << Move Selected Columns( Expr(list), To first)) ); ``````
Highlighted
Staff

## Re: Move Selected Columns() with list parameter

I'm glad to hear a workaround has been found. In the meantime, we reported this issue to development, and JMP 15 (available later this year) has been updated so that the evaluation will happen automatically. Thanks!

Article Labels

There are no labels assigned to this post.