Dear all
I'm a bit surprised by the results output from nzchar(). The help page
says: "nzchar is a fast way to find out if elements of a character
vector are *non-empty strings*." (my emphasis. However, if you do
> x <- c(letters, NA, '')
> nzchar(x)
 [1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[13]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[25]  TRUE  TRUE  TRUE FALSE
> any(is.na(x))
[1] TRUE

the NA value in the character vector will be considered as a non-empty
string, something that I find strange. At best NA is the equivalent of
an empty string. In this sense, if you Hmisc::describe() the vector
you get, as I would expect, that in the context of character vectors
NA and '' values are considered together:
> require(Hmisc)
> describe(x)
x
      n missing  unique
     26       2      26

lowest : a b c d e, highest: v w x y z

So is this a bug in the function or in the help page? Regards
Liviu


-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

______________________________________________
R-help@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.

Reply via email to