[R] Removing Zeros from matrix

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Tue Mar 9 11:19:28 CET 2010


one approach is the following:

mat <- matrix(rnorm(100*45), 100, 45)
mat[sample(100*45, 50)] <- 0

index <- rowMeans(mat == 0) == 0
mat[index, ]


I hope it helps.

Best,
Dimitris


On 3/9/2010 11:05 AM, ogbos okike wrote:
> Hi Everybody,
> I have a matrix of about 45 columns. Some of the rows contain zeros. Using
>> data1<-data[complete.cases(data),], I can remove the "NA" rows. But I am
> unable to tackle that of zeros.
> Can anybody give me an idea of how to remove rows containing zeros in a
> matrix.
> Thanks so much
> Best
> Ogbos
>
> 	[[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.
>

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014



More information about the R-help mailing list