[R] String comparison, trailing blanks make a difference.
John McKown
john.archie.mckown at gmail.com
Fri Jul 18 18:17:30 CEST 2014
Well, this was a shock to me. And I don't really see any documentation
about it, but perhaps I just can't see it.
>"abc" == "abc "
[1] FALSE
I guess that I thought of strings in R like I do is some other
languages where the shorter value is padded with blanks to the length
of the longer value, then compared. I.e. that trailing blanks didn't
matter.
The best solution that I have found is to use the str_trim() function
from the stringr to remove all the trailing blanks after I get the
data from the SQL data base. I cannot change the SQL schema to make
the column a varchar instead of a char column. It is a vendor DB. And
I don't know an ANSI SQL standard way to remove trailing blanks in the
SELECT command. PostgreSQL has a "trim(trailing ' ' from column)', but
MS-SQL upchucks on that syntax.
--
There is nothing more pleasant than traveling and meeting new people!
Genghis Khan
Maranatha! <><
John McKown
More information about the R-help
mailing list