Is the fact that 0 is a possible and interesting value (even in being absent) a property of the table? Or a property of the variable?
I would argue that it is probably a property of the variable, and this is the better way to work with it in R (some older programs forced us to specify this at the analysis stage and it can take a bit of an effort to break that habit and do the more sensible approach). I would convert your data to factors (or ordered factors) and specify the levels, then table just works on its own: # untested code > s2 <- as.data.frame( lapply(s, function(x) factor(x, levels=0:1) ) ) > table( s2[,c(1,3)] ) Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [email protected] 801.408.8111 > -----Original Message----- > From: [email protected] [mailto:r-help-boun...@r- > project.org] On Behalf Of Shubha Vishwanath Karanth > Sent: Saturday, April 24, 2010 7:59 AM > To: [email protected]; [email protected] > Subject: [R] table command > > Hi, > > > > Let s be a dataframe. > > > > > s > > A B C > > 0 0 1 > > 1 0 1 > > 1 0 1 > > 0 0 1 > > 1 0 1 > > 0 1 1 > > 0 1 1 > > 0 1 1 > > 0 0 1 > > > > > tab1=table(s[,c(1,2)]) > > > tab1 > > B > > A 0 1 > > 0 3 3 > > 1 3 0 > > > > > tab2=table(s[,c(1,3)]) > > > tab2 > > C > > A 1 > > 0 6 > > 1 3 > > > > > > The problem is I need to access frequency corresponding to (0,0). > tab1[1] will give me the correct value while tab2[1] will not give the > frequency which I expected. So, is there a possibility in the table > command to have the order of tab1 and tab2 being equal? (here 2*2). May > be by filling in the appropriate value as 0 or NA? > > > > Thanks, > > Shubha > > > > This e-mail may contain confidential and/or privileged > i...{{dropped:13}} > > ______________________________________________ > [email protected] 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. ______________________________________________ [email protected] 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.

