[R] convert data.frame to matrix -> NA factor problem

Erik Iverson eriki at ccbr.umn.edu
Wed Jul 14 18:41:02 CEST 2010



syrvn wrote:
> Thanks again for your quick reply.
> 
> I understood your procedure but now it is even more strange why my
> conversion does not work.
> In your example, the NA values are in "brackets" <NA> and what your
> procedure does is to
> convert these <NA> values into NA and then it seems to be possible to use
> data.matrix to
> correctly convert the data.frame into a data.matrix. But the data I read
> into R are already in that
> form that the NA values are displayed as NA rather than <NA>. So the
> conversion should actually work.

Have not followed this thread, but I think you're confused about what a 
true NA value is, at least with factors.  When values of a factor are 
missing, they are printed <NA> to distinguish them from an actual factor 
level of NA.  Numeric missings are printed NA.

 > f1 <- factor("NA")
 > f1
[1] NA
Levels: NA
 > is.na(f1)
[1] FALSE

vs.

 > n1 <- c(NA)
 > n1
[1] NA
 > is.na(n1)
[1] TRUE



More information about the R-help mailing list