Skip to content
Prev 67573 / 398506 Next

How to plot Contour with NA in dataframe

"Duncan Murdoch" <murdoch at math.aau.dk> wrote in message
news:425CFE4D.8010208 at math.aau.dk...
This looks unnecessarily complicated here, but appears to be necessary.  I
normally would try to use only "as.matrix" here but this can fail as shown
below, but sometimes can work.

R's "rules" about this conversion seem somewhat arbitrary to me.  Example 3,
in particular, doesn't make sense to me.  Can anyone share some insight on
what is going on?

==========================


Dummy.txt

1,2,3

4,5,6



# 1.  Integers, no missing values; "as.matrix" good enough for conversion

# Results make sense.
[1] "list"
[1] "data.frame"
V1 V2 V3

1  1  2  3

2  4  5  6
[1] "integer"
[1] "matrix"



==========================



Dummy.txt

1,,3

4,2.5,6



# 2.  Doubles, missing values; "as.matrix" good enough for conversion

# Results make sense.
V1  V2 V3

1  1  NA  3

2  4 2.5  6
[1] "double"
[1] "matrix"



==========================



Dummy.txt

1,,3



# 3.  Drop second row of data from 2 above.  Now instead of integers or
doubles,

# the type is "character" after using as.matrix?

# Results don't make sense.  Why did dropping the second row of data change

# the type to "character" here?
V1  V2 V3

1 "1" NA "3"
[1] "character"
[1] "matrix"

==========================



Dummy.txt

1,,3



# 4.  More complicated solution than 3 above, like what Duncan suggested,

# but this gives expected results
V1 V2 V3

1  1 NA  3
[1] "double"
[1] "matrix"



==========================


Thanks for any help in clarifying this R subtilty.

efg
--
Earl F. Glynn
Scientific Programmer
Stowers Institute for Medical Research