Re: [R] Removing Zeros from matrix

2010-03-09 Thread Paul Hiemstra
Dimitris Rizopoulos wrote: On 3/9/2010 1:36 PM, Paul Hiemstra wrote: Dimitris Rizopoulos wrote: 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, ] Dimitris, You use quite a complicated syntax to g

Re: [R] Removing Zeros from matrix

2010-03-09 Thread Paul Hiemstra
Dimitris Rizopoulos wrote: 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, ] Dimitris, You use quite a complicated syntax to get the index. I think the following syntax using apply is more easy to u

Re: [R] Removing Zeros from matrix

2010-03-09 Thread Dimitris Rizopoulos
On 3/9/2010 1:36 PM, Paul Hiemstra wrote: Dimitris Rizopoulos wrote: 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, ] Dimitris, You use quite a complicated syntax to get the index. I think the fo

Re: [R] Removing Zeros from matrix

2010-03-09 Thread Dimitris Rizopoulos
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 conta

[R] Removing Zeros from matrix

2010-03-09 Thread ogbos okike
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 Ogbo