[R] How to include NA's of a factor in table?

From: Heinz Tuechler <tuechler_at_gmx.at>
Date: Mon 10 Jul 2006 - 22:23:00 EST

Dear All,

Is there a better way to include NA's of a factor in the output of table() than using as.character()?
Admittedly, I do not understand the help page for table concerning the exclude argument applied to factors. I tried in different ways, but could not get NA to be included in the table, if not using as.character() (see example).


## example
fcv <- factor(c('a', NA, 'c'))

table(fcv)                # shows a, c
table(fcv, exclude='a')   # shows c
table(fcv, exclude="")    # shows a, c

table(fcv, exclude=NULL) # shows a, c
table(as.character(fcv), exclude=NULL) # shows a, c, NA
platform       i386-pc-mingw32                          
arch           i386                                     
os             mingw32                                  
system         i386, mingw32                            
status         Patched                                  
major          2                                        
minor          3.1                                      
year           2006                                     
month          07                                       
day            01                                       
svn rev        38471                                    
language       R                                        
version.string Version 2.3.1 Patched (2006-07-01 r38471)

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 10 22:28:09 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 11 Jul 2006 - 00:17:18 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.