[R] Inconsistent handling of character NA?

Raubertas, Richard richard_raubertas at merck.com
Mon Jul 21 19:44:46 CEST 2003

[R 1.7.1 on Windows XP Pro]

Since R allows missing values for character variables, why
are NA's not propagated by character manipulation functions?
For example:

> temp <- c("a", NA)
> temp
[1] "a" NA 
> is.na(temp)
> paste(temp[1], temp[2])
[1] "a NA"
> substr(temp, 1, 1)
[1] "a" "N"
> sub("[aA]","b", temp)
[1] "b"  "Nb"

It seems to me that paste(temp[1], temp[2]) should return
a single character NA: it asks to concatenate "a" with
some unknown string, so the result should be unknown as
well.  This is certainly how numeric NA's are handled.

Rich Raubertas
Biometrics Research, RY33-300
Merck & Co.

Notice: This e-mail message, together with any attachments, ...{{dropped}}

More information about the R-help mailing list