# Re: [R] Delete rows from matrix having at least one zero value

From: stephen sefick <ssefick_at_gmail.com>
Date: Sun, 09 Nov 2008 15:03:56 -0500

# I think this does what you want
d <- rbind(c(1, 0, 6, 4),

```c(2,    5,   7,    5),
c(3,    6,    8,    6),
c(4,    0,    0,    0))
```

f <- as.matrix(d)
f[-which(rowSums(f==0)>0),]

On Sun, Nov 9, 2008 at 8:30 AM, mentor_ <mentor__at_gmx.net> wrote:
>
> Have found a solution:
>
> matrix[rowSums(matrix == 0) == 0, ]
>
>
>
> mentor_ wrote:
>>
>> Hi,
>>
>> I have a further question about matrix manipulation.
>>
>> Imagine the following two matrices:
>>> test
>> [,1] [,2] [,3] [,4]
>> [1,] 1 0 6 4
>> [2,] 2 5 7 5
>> [3,] 3 6 8 6
>> [4,] 4 0 0 0
>>
>>> matrix(is.element(test,0), ncol=4)
>> [,1] [,2] [,3] [,4]
>> [1,] FALSE TRUE FALSE FALSE
>> [2,] FALSE FALSE FALSE FALSE
>> [3,] FALSE FALSE FALSE FALSE
>> [4,] FALSE TRUE TRUE TRUE
>>
>> How can I apply the TRUE FALSE matrix to the 'test' matrix so that all
>> rows
>> having at least one zero value will be thrown out.
>>
>> So after applying the TRUE FALSE matrix the test matrix shoud look like
>> the following:
>> [,1] [,2] [,3] [,4]
>> [1,] 2 5 7 5
>> [2,] 3 6 8 6
>>
>> Cheers
>>
>
> --
> View this message in context: http://www.nabble.com/Delete-rows-from-matrix-having-at-least-one-zero-value-tp20405964p20406333.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.
>

```--
Stephen Sefick
Research Scientist

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help