キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
言語を選択 翻訳バーを非表示
gallardet
Level III

Delete all columns that have zeros in all raws

Well, that is what I need to do.

I tried to look for similar scripts but I have not found the solution.

Thanks in advance.

 

Manel

1 件の受理された解決策

受理された解決策
txnelson
Super User

Re: Delete all columns that have zeros in all raws

Here is a simple script that will delete all columns that are all zeros

Names Default To Here( 1 );
dt = Current Data Table();

numericColNames = dt << get column names( string, numeric );

allZerosList = {};

For( i = 1, i <= N Items( numericColNames ), i++,
	If( Col Sum( Column( dt, numericColNames[i] ) ) == 0
	& Col Std Dev( Column( dt, numericColNames[i] ) ) == 0,
		Insert Into( allZerosList, numericColNames[i] )
	)
);

If( N Items( allZerosList ) > 0,
	dt << delete columns( allZerosList )
); 
Jim

元の投稿で解決策を見る

5件の返信5
ron_horne
Super User (Alumni)

Re: Delete all columns that have zeros in all raws

txnelson
Super User

Re: Delete all columns that have zeros in all raws

Here is a simple script that will delete all columns that are all zeros

Names Default To Here( 1 );
dt = Current Data Table();

numericColNames = dt << get column names( string, numeric );

allZerosList = {};

For( i = 1, i <= N Items( numericColNames ), i++,
	If( Col Sum( Column( dt, numericColNames[i] ) ) == 0
	& Col Std Dev( Column( dt, numericColNames[i] ) ) == 0,
		Insert Into( allZerosList, numericColNames[i] )
	)
);

If( N Items( allZerosList ) > 0,
	dt << delete columns( allZerosList )
); 
Jim
gallardet
Level III

Re: Delete all columns that have zeros in all raws

Thanks, Sir.
TRR21
Level III

Re: Delete all columns that have zeros in all raws

Can this be tweaked such that I can remove columns that have mostly zeros (eg. 50% of more of the rows)?

Thanks.
txnelson
Super User

Re: Delete all columns that have zeros in all raws

You could do something like:

If(
	N Rows( dt << get rows where( Column( dt, numericColNames[i] ) == 0 ) ) >
	N Rows( dt ) / 2,
	Insert Into( allZerosList, numericColNames[i] )
);
Jim

おすすめの記事