Skip to content
Prev 10506 / 63421 Next

bug or feature? (PR#4150)

On Sat, 13 Sep 2003 13:37:28 +0200 (MET DST), you wrote:

            
No, the general rule in R is that operators try to coerce their
arguments into a suitable type for the operation.  In this case,
because one arg is character, the other one is coerced to character
too.  It doesn't matter that you forced the type using as.numeric or
as.character; the operator is going to force them both to comparable
types.

For example,
[1] "3.14159265358979"
[1] TRUE
[1] FALSE

In the last case, they were already comparable, so no forcing was
done.  Since the internal value of pi actually carries more than 14
decimal places of precision, they don't compare equal as numbers, even
though the do compare equal when converted to character.

If you want to distinguish numbers and characters, use mode(1) ==
mode("1").

Duncan Murdoch