[This issue has been covered by other correspondents, but I wanted to
clarify a couple of points.]
There is no way for character vectors (objects of mode character) in S-PLUS
to contain a missing value (NA). The reason is largely historical: the
internal representation does not allow for it.
If you need to represent missing values in character vectors, you have two
options:
1. Use a coded value to represent missing values and test for it explicitly.
For example, ifelse(mycharvec="**MISSING**", <non-missing-values>,
<missing-values>). An empty string "" may make a suitable representation
for missing values in some cases.
2. Use an object of class 'factor', which may contain NAs.
When coercing from other modes to character, NAs become the string "NA".
The converse is not true, and deliberately so: the string "NA" appears
fairly often in practice as a data value (as an abbreviation for North
America or as the stock ticker symbol for Nabisco Corp, for example).
The "string" class as described in the Green Book (Programming With Data,
Chambers) isn't supported in S-PLUS. While much of Sv4 as described in the
Green Book was incorporated into S-PLUS, that book does not describe S-PLUS
version 6 (and has some discrepancies with it, of which this is a major
example). Some of the support functions for the "string" class do exist in
S-PLUS as they're used by some internal code, but they are not intended for
general use and documented as such. As a point of nomenclature (and just to
keep you on your toes), I was using the word "string" above in the usual
programmer's sense, to refer to a single element of a character vector.
# David Smith
--
David M Smith <dsmith@insightful.com>
S-PLUS Product Marketing Manager, Insightful Corp, Seattle WA
Tel: +1 (206) 283 8802 x360
Fax: +1 (206) 283 0347
Insightful Corporation provides analytical solutions leveraging
S-PLUS, StatServer, S-PLUS Analytic Server and consulting services.
See www.insightful.com for details.
> -----Original Message-----
> From: s-news-owner@lists.biostat.wustl.edu
> [mailto:s-news-owner@lists.biostat.wustl.edu]On Behalf Of Vadim Kutsyy
> Sent: Thursday, December 06, 2001 15:11
> To: S-News (E-mail)
> Subject: [S] NA's in string vector.
>
>
> Is there a way to define NA's in string vector?
>
> > a<-c("a",NA,"b")
> > is.na(a)
> [1] F F F
> > a
> [1] "a" "NA" "b"
> > a[2]<-NA
> > is.na(a)
> [1] F F F
>
> Splus converge all NA's to "NA", which make problem in data.frames.
>
> Thanks,
> ===================================================================
> Vadim Kutsyy, PhD http://www.kutsyy.com
> vkutsyy@cytokinetics.com vadim@kutsyy.com
> Statistician tel. 650-624-3218
> Cytokinetics, Inc fax. 650-624-3010
> 280 East Grand Avenue
> South San Francisco, CA 94080 http://www.cytokinetics.com
> ===================================================================
> ---------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu. To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message: unsubscribe s-news
|