It seems obvious to me that the empty string "" is length 0. cheers Worik [[alternative HTML version deleted]]
"" is a character vector with one element in it. ?nchar ?length>>>From: Worik R <worikr@gmail.com> To:r-help <r-help@r-project.org> Date: 11/Nov/2011 1:21p Subject: [R] Why does length("") == 1? It seems obvious to me that the empty string "" is length 0. cheers Worik [[alternative HTML version deleted]] ______________________________________________ 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. [[alternative HTML version deleted]]
On Thu, Nov 10, 2011 at 4:17 PM, Worik R <worikr at gmail.com> wrote:> It seems obvious to me that the empty string "" is length 0.You are using the wrong function to find the length of a character string. length() returns the length of the object, and length of (non-NULL) scalars is always 1. If you want the number of characters in a string, use nchar():> nchar("")[1] 0 Peter
'The R Inferno' Circle 8.1.66 http://www.burns-stat.com/pages/Tutor/R_inferno.pdf On 11/11/2011 00:17, Worik R wrote:> It seems obvious to me that the empty string "" is length 0. > > cheers > Worik > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- Patrick Burns pburns at pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno')