非表示にしたい NA とゼロを含む対角行列があります。
na.print = "" は正常に動作していますが、zero.print = "." 0.00 を != 0 として扱っているようです ?
これは、印刷された実行可能な例です。これにより、私が何を意味するかがわかります。
x <- matrix(c(0.01, NA, NA, NA, 0.00, 0.00, NA, NA, 0.00, 0.00, -0.01, NA, 0.00, 0.00, 0.00, 0.00), nrow=4, byrow=TRUE)
x
[,1] [,2] [,3] [,4]
[1,] 0.01 NA NA NA
[2,] 0.00 0 NA NA
[3,] 0.00 0 -0.01 NA
[4,] 0.00 0 0.00 0
print.table(x, na.print="", zero.print=".")
[,1] [,2] [,3] [,4]
[1,] 0.01
[2,] 0.00 0.00
[3,] 0.00 0.00 -0.01
[4,] 0.00 0.00 0.00 0.00
以下の役立つ回答に従って (ありがとう!)、print.table での not zero.print items の明示的な選択に基づいて、テーブル内の任意の項目が失敗する (x == round(x))、ここで動作するバージョンを次に示します。浮動小数点。データフレームの印刷タスク用に作成しましたが、マトリックスで動作します。
print.dataframe <- function (x, digits = getOption("digits"), quote = FALSE, na.print = "", zero.print = "0", justify = "none", ...){
xx <- format(x, digits = digits, justify = justify)
if (any(ina <- is.na(x)))
xx[ina] <- na.print
i0 <- !ina & x == 0
if (zero.print != "0" && any(i0))
xx[i0] <- zero.print
if (is.numeric(x) || is.complex(x)){
print(xx, quote = quote, right = TRUE, ...)
}else{
print(xx, quote = quote, ...)
}
invisible(x)
}
print.dataframe(bob, zero.print = ".", justify="left")