[R] number of zeros in a matrix -row by row

onyourmark william108 at gmail.com
Mon Apr 6 16:12:56 CEST 2009


oh boy, what a mistake. Ok, I will try that and look up what it means
afterward.
Thank you.

MUHC-Research wrote:
> 
> Hi,
> 
> Try
> 
> /rowSums(M==0)/
> 
> This should work just fine.
> 
> Cheers,
> 
> Luc
> 
> onyourmark wrote:
>> Hi. I have an n x m matrix M some of who's entries are zeros. I want to
>> know
>> how many zeros there are in each row    -perhaps stored in a 1 x n vector
>> which lists the number of zeros for each row of M.
>>
>> Before I had a vector V and I was able to get the number of zeros in V by
>> doing length(V[ V==0]) but when I try something similar for M, like M[
>> M==0]
>> it creates a vector not a matrix and so this does not work. Does anyone
>> have
>> a solution to this?
>>
>> Thank you.
>>
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/number-of-zeros-in-a-matrix--row-by-row-tp22893147p22909577.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list