Hi everyone! This is a ridiculously simple problem, I just can't seem to find the solution! All I need is something equivalent to sum(is.na(x)) but instead of counting missing values, to count empty cells (with a value of 0). A naive attempt with is.empty didn't work :) Thanks! Maja Oh, and if the proposed solution would be to make all the empty cells into missing cells, that is not an option! There are over 20,000,000 cells in my table, and I don't think my computer is in the mood to store two such objects! -- View this message in context: http://n4.nabble.com/count-number-of-empty-cells-in-a-table-matrix-data-frame-tp947740p947740.html Sent from the R help mailing list archive at Nabble.com.
Greg Snow
2009-Dec-03 18:22 UTC
[R] count number of empty cells in a table/matrix/data.frame
If you only want to count cells that are exactly 0.0 (not slightly different due to rounding errors) then try:> sum( x==0 )If you want a little wiggle room for rounding error, then you can try something like:> sum( -0.0000001 < x & x < 0.0000001 )Adjusting the number of 0's as you see fit. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of maiya > Sent: Thursday, December 03, 2009 9:29 AM > To: r-help at r-project.org > Subject: [R] count number of empty cells in a table/matrix/data.frame > > > Hi everyone! > > This is a ridiculously simple problem, I just can't seem to find the > solution! > > All I need is something equivalent to > > sum(is.na(x)) > > but instead of counting missing values, to count empty cells (with a > value > of 0). > > A naive attempt with is.empty didn't work :) > > Thanks! > > Maja > > Oh, and if the proposed solution would be to make all the empty cells > into > missing cells, that is not an option! There are over 20,000,000 cells > in my > table, and I don't think my computer is in the mood to store two such > objects! > -- > View this message in context: http://n4.nabble.com/count-number-of- > empty-cells-in-a-table-matrix-data-frame-tp947740p947740.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 > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.