[Rd] dist() objects with NA's don't print them (PR#4866)
maechler at stat.math.ethz.ch
maechler at stat.math.ethz.ch
Thu Oct 30 15:40:39 MET 2003
The print.dist() method in the mva package currently prints the
triangular distance matrices with the ``trick'' of setting the
(diagonal and) upper triangular part to NA, and then uses
print(mat, na = "") to print that matrix.
This is very much undesired if there are true NAs.
Reproducible example code:
(x <- cbind(c(1,NA,2,3), c(NA,2,NA,1)))
(d <- dist(x)) ## does not show the NAs
as.matrix(d) ## now you see them
-- Transcript :
> (x <- cbind(c(1,NA,2,3), c(NA,2,NA,1)))
[,1] [,2]
[1,] 1 NA
[2,] NA 2
[3,] 2 NA
[4,] 3 1
> (d <- dist(x)) ## does not show the NAs
1 2 3
2
3 1.414214
4 2.828427 1.414214 1.414214
> as.matrix(d) ## now you see them
1 2 3 4
1 0.000000 NA 1.414214 2.828427
2 NA 0.000000 NA 1.414214
3 1.414214 NA 0.000000 1.414214
4 2.828427 1.414214 1.414214 0.000000
>
---------
The fix is to rewrite print.dist() by not using the above trick
-- which I have almost finished and will commit to R-patched.
Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
More information about the R-devel
mailing list