[R] zero.print in print.table after adding margins

BXC (Bendix Carstensen) bxc at steno.dk
Thu Jun 29 11:34:41 CEST 2006


The function addmargins() adds margins to a table, but returns a matrix.
But even after converted to a table the print.zero="." option of
print.table() does not work:

> x <- sample( 1:7, 20, replace=T )
> y <- sample( 1:7, 20, replace=T )
> tt <- table( x, y )
> tx <- as.table( addmargins( table( x, y ) ) )
> print( tt, zero.print="." )
   y
x   1 2 3 4 5 6 7
  1 1 2 2 . . 1 .
  2 1 . . 1 . . .
  3 . . . . . . 2
  4 1 . . . . 1 .
  5 1 . 1 . . 1 .
  6 . 1 . 1 . . .
  7 . . 1 . 1 1 .
> print( tx, zero.print="." )
     y
x      1  2  3  4  5  6  7 Sum
  1    1  2  2  0  0  1  0   6
  2    1  0  0  1  0  0  0   2
  3    0  0  0  0  0  0  2   2
  4    1  0  0  0  0  1  0   2
  5    1  0  1  0  0  1  0   3
  6    0  1  0  1  0  0  0   2
  7    0  0  1  0  1  1  0   3
  Sum  4  3  4  2  1  4  2  20

Is this a facility of print.table?
The attributes() of tt and tx have identical stucture. 

Best,
Bendix
----------------------
Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 30 75 87 38
fax: +45 44 43 07 06
bxc at steno.dk
www.biostat.ku.dk/~bxc



More information about the R-help mailing list