Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- JMP User Community
- :
- Discussions
- :
- Delete all columns that have zeros in all raws

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 10, 2019 1:13 PM
(1766 views)

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 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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 REPLIES 5

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Delete all columns that have zeros in all raws

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Delete all columns that have zeros in all raws

Thanks, Sir.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.

Thanks.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Article Labels

There are no labels assigned to this post.