[R] display of character NA's in a dataframe in 1.5.0
David Kane <David Kane
a296180 at mica.fmr.com
Tue Apr 30 16:47:12 CEST 2002
I understand that NA's in character vectors are displayed differently than NA's
in factor vectors.
> c("x", NA, "y")
[1] "x" NA "y"
> as.factor(c("x", NA, "y"))
[1] x <NA> y
Levels: x y
That seems sensible enough. But shouldn't I see the same behavior in a dataframe?
> test <- data.frame(a = c("x", NA, "y"))
> test
a
1 x
2 <NA>
3 y
> is.factor(test$a)
[1] TRUE
> is.character(test$a)
[1] FALSE
This behavior is correct since R coerces `a' to be a factor as it constructs
the test dataframe. But consider what happens when I force `a' to be character:
> test$a <- as.character(test$a)
> is.factor(test$a)
[1] FALSE
> is.character(test$a)
[1] TRUE
> test
a
1 x
2 <NA>
3 y
The display is the same. I would have expected it to be something like:
> test
a
1 x
2 NA
3 y
If this is a bug, please let me know and I would be happy to submit it as
such. But, I suspect that it is more likely that there is something that I
don't fully understand about NA's and dataframes.
> R.version
_
platform sparc-sun-solaris2.6
arch sparc
os solaris2.6
system sparc, solaris2.6
status
major 1
minor 5.0
year 2002
month 04
day 29
language R
Thanks,
Dave Kane
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list