[R] NA vs. <NA>

Muenchen, Robert A (Bob) muenchen at utk.edu
Fri Apr 4 18:31:12 CEST 2008


Peter & Hadley, thanks for the clarification. The NA=North America example reminds me of a text analysis problem in which "TO" meant "Take Off" for pilots. Of course many text analysis programs toss supposedly low-information words like that! Thanks, Bob

> -----Original Message-----
> From: Peter Dalgaard [mailto:p.dalgaard at biostat.ku.dk]
> Sent: Friday, April 04, 2008 12:18 PM
> To: Muenchen, Robert A (Bob)
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] NA vs. <NA>
> 
> Muenchen, Robert A (Bob) wrote:
> > Dear R-Helpers,
> >
> > Why does R show character missing values in vectors as NA and when
> > stored in a data frame as <NA>? I've searched but did not find an
> > explanation.
> >
> > Thanks,
> > Bob
> >
> >
> >> gender <- c("f","f","f",NA,"m","m","m","m")
> >> gender
> >>
> > [1] "f" "f" "f" NA  "m" "m" "m" "m"  #here it lacks brackets.
> >
> >> q1 <- c(1,2,2,3,4,5,5,4)
> >> q1
> >>
> > [1] 1 2 2 3 4 5 5 4
> >
> >> myDF <- data.frame(q1,gender)
> >> myDF
> >>
> >   q1 gender
> > 1  1      f
> > 2  2      f
> > 3  2      f
> > 4  3   <NA>  #here it has brackets.
> > 5  4      m
> > 6  5      m
> > 7  5      m
> > 8  4      m
> >
> It is actually a factor in the latter case
> 
>  > data.frame(gender)$gender
> [1] f    f    f    <NA> m    m    m    m
> Levels: f m
> 
> However, you have the same effect with
> 
>  > data.frame(gender,stringsAsFactors=FALSE)
>   gender
> 1      f
> 2      f
> 3      f
> 4   <NA>
> 5      m
> 6      m
> 7      m
> 8      m
> 
> The thing to notice is that the printing is without the quote
> character.
> We also have
> 
>  > noquote(gender)
> [1] f    f    f    <NA> m    m    m    m
> 
> And the point in either case is that we need some way to distinguish
> between NA (missing) and "NA" (New Alliance, Noradrenalin, North
> America, Neil Armstrong, etc.)
> 
> --
>    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
>   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
>  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45)
> 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45)
> 35327907
> 



More information about the R-help mailing list