Skip to content
Prev 30230 / 398506 Next

Printing zero as dot

Many thanks to J.R. Lockwood and to Sundar Dorai-Raj for sending me
their suggestions. I ended up using Sundar's function blended with a
flavour of `zapsmall':

print.matrix2 <- function(x, zero = ".", digits=getOption("digits"), ...) {
    if (all(ina <- is.na(x))) 
        return(x)
    if (length(digits) == 0) 
        stop("invalid digits")
    mx <- max(abs(x[!ina]))
    x <- round(x, digits = if (mx > 0) 
               max(0, digits - log10(mx))
    else digits)
    zeros <- which(x == 0, arr.ind = TRUE)
    x[zeros] <- zero
    print(x, quote = FALSE, right = TRUE, ...)
    invisible()
}

Have a good weekend,
Giovanni

  
    
Message-ID: <200304042254.h34MsgMl010924@definetti.uark.edu>
In-Reply-To: <200304032154.h33LsCX7009631@definetti.uark.edu> (message from Giovanni Petris on Thu, 03 Apr 2003 15:54:12 -0600 (CST))