Hi list, I've encounter this problem (see below).? I know it's particularly R-related and it's easy to get by but it still bothers me a lot.? It looks the last character of "N.C. " is a space to me, but it's clearly not.? Can someone tell me a way to figure out what character is in the last position. Thanks! Tao> levels(dat$flag)[3][1] "N.C.?"> levels(dat$flag)[3]=="N.C. "[1] FALSE> substr(levels(dat$flag)[3],5,5)[1] "?"> substr(levels(dat$flag)[3],5,5)==" "[1] FALSE> "N.C.?"=="N.C. "?? ## NOTE: this last one can't be reproduced after copy-n-paste[1] FALSE
Use 'charToRaw' to see what the bytes making up the string are:> charToRaw('N.C. ')[1] 4e 2e 43 2e 20 On Wed, Nov 28, 2012 at 7:44 PM, Shi, Tao <shidaxia at yahoo.com> wrote:> Hi list, > > I've encounter this problem (see below). I know it's particularly R-related and it's easy to get by but it still bothers me a lot. > > > It looks the last character of "N.C. " is a space to me, but it's clearly not. Can someone tell me a way to figure out what character is in the last position. > > Thanks! > > Tao > > > >> levels(dat$flag)[3] > [1] "N.C. " >> levels(dat$flag)[3]=="N.C. " > [1] FALSE >> substr(levels(dat$flag)[3],5,5) > [1] " " >> substr(levels(dat$flag)[3],5,5)==" " > [1] FALSE >> "N.C. "=="N.C. " ## NOTE: this last one can't be reproduced after copy-n-paste > [1] FALSE > > ______________________________________________ > 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.-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
On Wed, Nov 28, 2012 at 4:44 PM, Shi, Tao <shidaxia at yahoo.com> wrote:> Hi list, > > I've encounter this problem (see below). I know it's particularly R-related and it's easy to get by but it still bothers me a lot. > > > It looks the last character of "N.C. " is a space to me, but it's clearly not. Can someone tell me a way to figure out what character is in the last position.Probably a non-breaking or other special space. You can try utf8ToInt on your character string to convert it to UTF-8 codes. Then look up the character by its code. HTH, Peter
On Wed, 28 Nov 2012 16:44:59 -0800 (PST) "Shi, Tao" <shidaxia at yahoo.com> wrote:> Hi list, > > I've encounter this problem (see below).? I know it's particularly > R-related and it's easy to get by but it still bothers me a lot.? > > > It looks the last character of "N.C. " is a space to me, but it's > clearly not.? Can someone tell me a way to figure out what character > is in the last position. > > Thanks! > > TaoIn the sample you provide it is HEX 20 which is ASCII for "space." So either, it really is a space, or it didn't copy in your message. I would suggest copying the string and pasting into a hex editor. Doing that with the "N.C. " from your message yields: 22 4E 2E 43 2E 20 22 The "20" is the ASCII "space" character. Just possibly, if you are using a file saved in a unicode format, it could be a "no-break space" - Unicode point U+00A0, or UTF-8 "c2 a0". Good luck. JWDougherty