Subscribe Bookmark RSS Feed

lockup columns

gianpaolo_polsi

Community Trekker

Joined:

Mar 23, 2016

Good morning,

starting from a discussion of a couple of week ago (here) , i have added to the solved script a simple GUI in order to select  the columns to be analyzed and  the % of stagnant or empty elements in such columns.

 

i want create a new columns to check  which columns of my table are almost empty or stagnant, but  

i have a problem that i'm not able to lock-up the processed columns to the main table,  in my script something is wrong,

can you help me

 

thanks in advance

here the code:

 

 

 

Names Default To Here( 1 );

clear globals();

 

 

 

// code to choose among all opened tables which one will be selected for the analysis

OpenDT = List();

For( i = 1, i <= N Table(), i++,

Insert Into( OpenDT, Data Table( i ) )

);

 

 

dlgDT = Dialog( "Select Data Table for analysis", VList( selectDT = List Box( OpenDT ) ), HList( Button( "OK" ), Button( "Cancel" ) ) );

 

Show( dlgDT );

If( dlgDT["button"] == 1,

Remove From( dlgDT, N Items( dlgDT ) );

Eval List( dlgDT );

);

 

Current Data Table( selectDT[1] );

 

 

 

// -----------------------------------------GUI -----------------------------------------//

cd = Column Dialog(

Title( " Columns screening " ),

List= ColList( " select Columns >> ", MinCol( 1 ) ),

HList( "% of empty column > (0-100)",

"% of stagnant columns < (0-100)", mypercent = EditNumber( 90 ) ),

);

 

 

 

//declaration of variables

 

percent = cd["mypercent"];

 

mylist = cd["List"];

 

dt= selectDT[1];

delcols = {};

 

 

numRows = nrows(dt);

for(i=1; maxi=Nitems(mylist), i<=maxi, i++,

if(nrows(loc(aslist(column(dt,mylist[i])<<getasmatrix),mode(column(dt,mylist[i])<<getasmatrix))) > numRows * percent/100,

insert into(delcols, i);

,

if(Col N Missing(column(dt,mylist[i])) > numRows * percent/100,

insert into(delcols, i);

);

);

);

 

 

nitems = N Items( delcols );

colname = {};

colnamelist = {};

For( p = 1, p <= nitems, p++,

colname = Column( delcols[p] ) << Get Name;

Insert Into( colnamelist, colname(p) );

);

 

 

subDt1 = dt << Subset (Columns(colnamelist), Output Table Name("check removed columns"));

 

  

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp

Staff

Joined:

Jun 23, 2011

Solution

I'm sorry, but I haven't looked at the details of your code, nor what it's trying to do. But maybe it should be:

 

		Insert Into( delcols, myList[i] )

rather than:

 

		Insert Into( delcols, i )
1 REPLY
ian_jmp

Staff

Joined:

Jun 23, 2011

Solution

I'm sorry, but I haven't looked at the details of your code, nor what it's trying to do. But maybe it should be:

 

		Insert Into( delcols, myList[i] )

rather than:

 

		Insert Into( delcols, i )