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: table(as.character(WC),as.character(WD),exclude=c()) Is there an easier way? I guess this is a feature request for table() Thanks, Robert. ---- Robert King, Australian Environmental Studies, Griffith University, Australia 3875 6677 Robert.King at mailbox.gu.edu.au http://www.ens.gu.edu.au/robertk/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Robert.King at mailbox.gu.edu.au writes:> 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: > > table(as.character(WC),as.character(WD),exclude=c()) > > Is there an easier way? > > I guess this is a feature request for table()It's a bit tricky: table() has this internally if (is.factor(a)) cat <- a else cat <- factor(a, exclude = exclude) Now if you do factor(a, exclude = exclude) unconditionally, and have exclude=NULL, you'll get the NA's in the table, but lose all levels not present in data, which can also be a pain... -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._