[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-help
Subject:    [R] as.character.factor when the factor contains "NA"
From:       "Brahm, David" <David.Brahm () geodecapital ! com>
Date:       2006-04-28 22:15:36
Message-ID: 4DD6F8B8782D584FABF50BF3A32B03D806867D37 () MSGBOSCLF2WIN ! DMN1 ! FMR ! COM
[Download RAW message or body]

as.character.factor contains this line (where cx=levels(x)[x]):
  if ("NA" %in% levels(x)) cx[is.na(x)] <- "<NA>"

Is it possible that this is no longer the desired behavior?  These
two results don't seem very consistent:

> as.character(as.factor(c("AB", "CD", NA)))
[1] "AB" "CD" NA  
> is.na(.Last.value)[3]
[1] TRUE

> as.character(as.factor(c("NA", "CD", NA)))
[1] "NA"   "CD"   "<NA>"
> is.na(.Last.value)[3]
[1] FALSE

I'm using R-2.3.0 on Redhat Linux, but I don't think the behavior
is new (maybe since character NA's were introduced?).

-- David Brahm (brahm@alum.mit.edu)

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic