[Rd] NA printing

Robin Hankin rksh1 at cam.ac.uk
Tue Jan 25 16:34:38 CET 2011


I'm writing a print method for an object that includes a numeric matrix
for which
the lower diagonal elements are not meaningful.  So I make the lower
diagonal of my matrix NA and print it.

But my co-author does not like NA there and wants a dash.

I have tried coercing the matrix to character, essentially by
M[is.na(M)] <- "-" but this interferes with the pleasing
column alignment for numerical matrices.

How do I make R print "-" instead of "NA"  for NA entries in a numeric
matrix, without altering the vertical alignment?  Is there such a command

options(NA_string = "-")


best wishes

Robin Hankin

More information about the R-devel mailing list