[R] String comparison, trailing blanks make a difference.
hpages at fhcrc.org
Fri Jul 18 19:56:43 CEST 2014
On 07/18/2014 09:17 AM, John McKown wrote:
> 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"
>  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
The shock to me is to learn that some programming languages consider
strings "abc" and "abc " to be the same. Please name them so I can stay
away from them ;-)
> 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.
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024
E-mail: hpages at fhcrc.org
Phone: (206) 667-5791
Fax: (206) 667-1319
More information about the R-help