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
On Mon, Aug 6, 2012 at 4:48 PM, Liviu Andronic <landronimirc at gmail.com> wrote:> 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: >By the way, same question holds for nchar(): Should NA values be reported as 2-char strings, or as 0-char empty/missing values?> x <- c(letters, NA, '') > nchar(x)[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 0 Liviu