Skip to content
Prev 7441 / 63421 Next

is.na<- coerces character vectors to be factors within dataframes (PR#1577)

I am not sure if this is a bug within is.na<- or if it lies deeper in the
dataframe construction process. Indeed, perhaps it is not a bug at all (in
which case I would suggest that the help page for NA be provided with a warning
for unsuspecting users (like me)).

When used on a character vector within a dataframe, is.na<- coerces the vector
to factor.
var
1   A
2   B
3   C
[1] TRUE
var
1    A
2   <NA>
3    C
[1] FALSE
[1] TRUE
Interestingly enough, this coersion does not occur if you refer to x$var
instead of x[[1]].
var
1    A
2   <NA>
3    C
[1] TRUE
[1] FALSE
I could (ort of) imagine a story in which the coercision is the desired
behavior --  by using is.na you are implicitly taking apart a dataframe and
putting it back together and, when you make dataframes, character vectors are
coerced to factor by default. But I can't come up with a story as to why x$var
should be handled differently then x[[1]].
_                   
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,

David Kane

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._