Skip to content
Prev 311474 / 398513 Next

Creating a frequency table for binomial varaible

Make a factor out of your data, specifying all the levels you want counts
for, and pass that factor to table().  E.g.,

   >   x <- rep(0:6, c(5,2,0,3,0,4,0))
   >   table(x)
   x
   0 1 3 5 
   5 2 3 4
   >   table(factor(x, levels=0:10))
   
    0  1  2  3  4  5  6  7  8  9 10 
    5  2  0  3  0  4  0  0  0  0  0

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com