[R] Printing zero as dot

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Fri Apr 4 20:41:25 CEST 2003


Giovanni Petris wrote:
> I'm pretty sure I've seen some examples of a function printing zero
> entries in a matrix as dots, but I'm not able to find it now...
> Any suggestions...? Thanks in advance. (Of course, I might have dreamt
> of such a function...) 
> 
> Best,
> Giovanni
> 

I just so have something that may help:

print.matrix2 <- function(x, zero = ".", ...) {
   zeros <- which(x == 0, arr.ind = TRUE)
   x[zeros] <- zero
   print(x, quote = FALSE, right = TRUE, ...)
   invisible()
}

 > print.matrix2(diag(5))
      [,1] [,2] [,3] [,4] [,5]
[1,]    1    .    .    .    .
[2,]    .    1    .    .    .
[3,]    .    .    1    .    .
[4,]    .    .    .    1    .
[5,]    .    .    .    .    1
 >

Sundar



More information about the R-help mailing list