Skip to content

matrix() can't handle NaN (PR#193)

4 messages · Bill Simpson, Kurt Hornik, Ben Bolker

#
Full_Name: Bill Simpson
Version: 0.64.1
OS: linux
Submission from: (NULL) (193.62.250.209)


Here is the data file:
x y z
1 1 1
1 2 2
2 1 NaN
2 2 4
x y   z
1 1 1   1
2 1 2   2
3 2 1 NaN
4 2 2   4
[,1] [,2]
[1,]    1    4
[2,]    2    3

This is not the correct matrix.  It seems that NaNs screw up matrix().

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Actually, data$z is a factor with one level NaN.

R> data$z
[1] 1   2   NaN 4  
Levels:  1 2 4 NaN

What you get is the codes of that, which I think is what you want.

-k
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Perhaps this should be in a FAQ list ...
x y  z
1 1 1  1
2 1 2  2
3 2 1 NA
4 2 2  4
[,1] [,2]
[1,]    1   NA
[2,]    2    4

  "NaN" (Not a Number) as seen in debuggers, etc., is not the same as "NA"
as a "not available/applicable" value in R.
On Tue, 11 May 1999, Bill Simpson wrote:

            
Benjamin Bolker          Dep't of Ecology and Evolutionary Biology,
ben@eno.princeton.edu    Princeton University
tel: (609) 258-6886,     fax: (609) 258-1334

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Tue, 11 May 1999, Kurt Hornik wrote:

            
I forgot these steps:
x<-unique(data$x)
y<-unique(data$y)
Geez, I why is data$z a factor?  That seems bizarre. It is supposed to be
the measured value (IV) at each combination of x and y. So what is the
right way to convert my original file?

I go through all this just to produce an image or contour or persp plot.
Weird! Is this because matrix() interprets NaN as a character string
instead of as an NaN (which is a "number", isn't it?)?

Why then isn't everything converted to a factor?
[1] 1 1 2 2
[1] 1 2 1 2

Also, why does matrix() work as I expect when the NaN in the file is
changed to a 0:
[,1] [,2]
[1,]    1    0
[2,]    2    4

It also works as I expect when the NaN is changed to an NA:
[,1] [,2]
[1,]    1   NA
[2,]    2    4
NOPE! I want a matrix:
1	NaN
2	4

Bill

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._