Ich habe Diagonalmatrizen mit NAs und Nullen, die ich verstecken möchte.So unterdrücken Sie den Nulldruck in einer Tabelle (zero.print = "" funktioniert nicht)
na.print = "" funktioniert einwandfrei, aber zero.print = "." scheint 0,00 als! = 0 zu behandeln?
Hier ist ein lauffähiges Beispiel mit Druck, so können Sie sehen, was ich meine: (! Danke Jungs)
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
die hilfreichen Antworten unten Nach und in print.table auf die explizite Wahl basierend auf nicht Null .print-Elemente, bei denen ein Element in der Tabelle fehlschlägt (x == round (x)), hier ist eine Version, die mit floating.point funktioniert. Ich habe es für eine Datendruck-Aufgabe geschrieben, aber es funktioniert mit Matrizen. Hier
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")
Da 'table' Objekte implizit davon ausgehen, dass alle Elemente Integer sind, funktioniert' print.table' nicht für Ihre Daten. – Andrie