Subscribe Bookmark RSS Feed

Delete columns in different tables

geof2

Community Trekker

Joined:

Sep 27, 2013

Hi,

I try to delete columns on multiple tables.

In the second  For loop I have an invalid argument.  but works on the first table only...

Thanks

geof

Open("D:\A.csv");

Open("D:\B.csv");

Open("D:\C.csv");

t_count = N Table();

For(i = 1, i <= t_count, i++,

     dt=Data Table(i);

     N = N Col(dt);

     ColumnstoKeep={"AA","BB"};

     ColumnstoTrash = {};

     For( j = 1, j <= N, j++,

          colname = Column( j ) << getname();            / Debugger said invali argument  !?/

          If( Contains( ColumnstoKeep, colname ) < 1,

               Insert Into( ColumnstoTrash, colname )

          );
     ) ;

     dt << delete columns( ColumnstoTrash );

);

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

geof2,

Your use of the column() function lacks a reference to the specific datatable you need, so you are operating on the current table only.  This is the C.csv table, that last one you opened.  Use Column( dt, j ).  So, for your second loop, use:

For( j = 1, j <= N, j++,

  

          colname = Column( dt, j ) << getname();

          If( Contains( ColumnstoKeep, colname ) < 1,

               Insert Into( ColumnstoTrash, colname )

          );

     ) ;

I also recommend that you use something other than j for your index.  j is a reserved function in JMP.

Michael

2 REPLIES
Solution

geof2,

Your use of the column() function lacks a reference to the specific datatable you need, so you are operating on the current table only.  This is the C.csv table, that last one you opened.  Use Column( dt, j ).  So, for your second loop, use:

For( j = 1, j <= N, j++,

  

          colname = Column( dt, j ) << getname();

          If( Contains( ColumnstoKeep, colname ) < 1,

               Insert Into( ColumnstoTrash, colname )

          );

     ) ;

I also recommend that you use something other than j for your index.  j is a reserved function in JMP.

Michael

geof2

Community Trekker

Joined:

Sep 27, 2013

Thanks very much :-)