So, I have the following matrix m:

```
       [,1] [,2] [,3] [,4] [,5]
    v1    0    1    2    3    3
    v2    1    1   NaN   4    4
    v3    2    2    2    3    4
    v4   NaN   3    3    4    5
    v5    4   NaN   4    5    5

```

and I need to eliminate the columns (and rows) that have NaN.
I found several easy ways to do it, like:

```
m[,!is.nan(colSums(m))]

```

for columns, but I want to use apply.

I tried using this (sol 1):

```
m[,!is.nan(apply(m,1,sum))]

```

but it shows me the first two columns.

I finally came up with this (sol 2):

```
m2[,!as.logical(colSums(-apply(m2, 2, is.nan)))]

```

But I think that solution is not that elegant.

Is there a way to make it shorter? 
Also, why does my first solution not work?