[R] NAs introduced by coercion in dist()

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Wed May 2 16:17:03 CEST 2007

slomascolo wrote:
> I work with Windows and use R version 2.4.1. I am JUST starting to learn this
> program...
> I get this warning message 'NAs introduced by coercion' while trying to
> build a distance matrix (to be analyzed with NMDS later) from a 336 x 100
> data matrix.  The original matrix has lots of zeros and no missing values,
> but I don't think this should matter.
> I searched this forum and people have suggested that the warning should be
> ignored but when I try to print the distance matrix I only get the row
> numbers (the matrix seems to be 'empty') and I'm not being able to judge
> whether the matrix worked or not.
> To get the distance matrix I wrote:
> dist.PxMx <- dist (PeaksMatrix, method='euclidean', diag=FALSE, upper=FALSE)
> I tried including the p argument (included in the help for dist()) and
> leaving it out, but that didn't seem to change anything.  I think that's
> required for one distance measure though, not for euclidean dist. 
> Should I really ignore this warning? If so, why am I not being able to see
> the distance matrix?
That error message is often generated by things like

> as.numeric("X")
[1] NA
Warning message:
NAs introduced by coercion

so the immediate suspicion is that your data are not what you think they

The output of str(PeaksMatrix) should be illuminating.

   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907

More information about the R-help mailing list