[R] removing zero rows from matrix/table

From: Patrick Zimmermann <brassnotdead_at_googlemail.com>
Date: Tue, 22 Apr 2008 11:52:08 +0200


Dear R-community,
I have matrices/tables of different sizes which may contain rows with only zeros. Now I would like to delete these zero lines or create new matrices composed only of the non-zero lines. Columns only containing zeros I want to preserve.
Here an example:

[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 1 0 1 1 0 0 0
[2,] 0 0 0 0 0 0 0
[3,] 1 0 0 0 0 0 0
[4,] 1 0 1 1 1 1 1
[5,] 1 0 1 0 1 0 1
[6,] 0 0 1 1 1 1 1
[7,] 0 0 0 0 0 0 0

Rows 2 and 7 shall be deleted, but column 2 shall be maintained. I believe this should be a simple operation with basic commands, but have no idea how to manage it.
Looking forward do any help,
Patrick



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 Tue 22 Apr 2008 - 09:55:37 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 Tue 22 Apr 2008 - 11:30:30 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.

list of date sections of archive