[R] including NAs in a table

John Logsdon j.logsdon at lancaster.ac.uk
Tue Nov 16 11:25:33 CET 1999



On Tue, 16 Nov 1999 Robert.King at mailbox.gu.edu.au wrote:

> I have two factors, WC and WD.  If I want a table including all the values
> of each factor, including NAs, I can get a table by going:
                  ^^^^^^^^^^^^

This is not a factor level, which is the root of the problem.

> 
> table(as.character(WC),as.character(WD),exclude=c())
> 
> Is there an easier way?
> 

So another way (equally ugly) is 

  table(ifelse(is.na(WC),'Something',WC),ifelse(is.na(WD),'else',WD))

You effectively have to extend the factor levels in some way.  Note it
doesn't work to have the two strings as 'NA'!  If the labels are numeric
then you can use an unused number (like 0) and the table will be ordered
numerically.

> I guess this is a feature request for table()
> 

Perhaps incl.na=F (default)?? 

John


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list