s-news
[Top] [All Lists]

Re: NA assignment for character vector

To: s-news@lists.biostat.wustl.edu
Subject: Re: NA assignment for character vector
From: David Brahm <brahm@alum.mit.edu>
Date: Wed, 26 Feb 2003 10:10:17 -0500
Cc: slake@hsph.harvard.edu
References: <Pine.GSO.4.53.0302251140360.5708@hsph.harvard.edu>
Reply-to: brahm@alum.mit.edu
Stephen Lake <slake@hsph.harvard.edu> wrote:
> > vec <- letters[1:5]
> > vec[4] <- NA
> > vec
> [1] "a" "b" "c" "NA" "e"
> > is.na(vec)
> [1] F F F F F

But note this behavior:
S> vec[c(1,NA,3)]
   [1] "a" ""  "c"
suggesting that in S-Plus, "" is the analog of numeric NA.  You could write:
S> vec <- letters[1:5]
S> vec[4] <- ""
S> vec
   [1] "a" "b" "c" "" "e"
S> vec==""
   [1] F F F T F

The string "NA" is certainly a bad choice, as it might represent the ticker for
Nabisco, the initials of Neil Armstrong, the symbol for Nitric Acid,...  But
you might also think "" is a bad choice if "" is a valid value for your
variable.

Note the R developers went down a different path, and created a true "missing"
character element <NA> in R.
-- 
                              -- David Brahm (brahm@alum.mit.edu)

<Prev in Thread] Current Thread [Next in Thread>