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

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Sun, 09 Nov 2008 14:42:17 -0500

Dear mentor_,
Try also

yourmat <- matrix(c(

```1,    0,    6,    4,
2,    5,   7,    5,
3,    6,    8,    6,
4,    0,    0,    0
),ncol=4,byrow=TRUE)

```

yourmat[apply(yourmat,1,function(x) sum(x==0)<1),]

HTH, Jorge

On Sun, Nov 9, 2008 at 7:39 AM, mentor_ <mentor__at_gmx.net> 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-tp20405964p20405964.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
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 09 Nov 2008 - 19:45:46 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 09 Nov 2008 - 20:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.