Skip to content

Setting NA to blank

6 messages · John Kane, Dat Mai, (Ted Harding) +1 more

#
(mat <- matrix(c(1,2,3,NA),2))
mat[is.na(mat)]   <- " "
mat

But if you have a numerical matrix it coverts the matrix to character.
--- On Mon, 5/9/11, Dat Mai <dat.d.mai at gmail.com> wrote:

            
#
John Kane's reply sums it up! (Though you could use "",
instead of " ", which would give you an "empty string"
instead of the "space" character; but the resulting
matrix would still consist entirely of "character"
elements).

However, the real reason I am following up is to ask
why you want the blank instead of the NA.

If it is just for printing out or display, then the
fact that the matrix has been converted to character
probably does not matter.

But if it is for compatibility with some other
computational software that (e.g.) expects missing
values to be represented by a blank, or some "null"
representation, then it may not be so straightforward.

So, if that might be an issue, please describe for us
how you intend to use the result.

Ted.
On 09-May-11 19:56:39, Dat Mai wrote:
--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 09-May-11                                       Time: 21:21:07
------------------------------ XFMail ------------------------------
#
Hi
being
NA
value
the
question
If you used heatmap function from stats package I believe that NA values 
are not displayed so they appear as white. So basically you should not 
need any change.

It is usually better then assume what you think the functions are doing to 
learn what they actually do by consulting help page. 

You could also try examples provided at bottom of almost each help page 
and modify it to suit your needs.

Regards
Petr
<ted.harding at wlandres.net>wrote:
wrote:
character.
http://www.R-project.org/posting-guide.html