Re: [R] NA vs. <NA>

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Fri, 04 Apr 2008 18:17:58 +0200

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 04 Apr 2008 - 16:20:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 04 Apr 2008 - 17:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive