[R] "--" < 0

peter dalgaard pd@|gd @end|ng |rom gm@||@com
Tue Jun 25 10:36:20 CEST 2024


Also notice that

> "+5" < 0
[1] TRUE

> as.numeric("+5") < 0
[1] FALSE

So the presumption is wrong. It is really about

> sort(c(0:3, "+", "-"))
[1] "-" "+" "0" "1" "2" "3"

-pd

> On 25 Jun 2024, at 10:02 , Martin Maechler <maechler using stat.math.ethz.ch> wrote:
> 
>>>>>> Adrian Dusa 
>>>>>>    on Tue, 25 Jun 2024 10:56:07 +0300 writes:
> 
>> Dear R fellows,
> 
>>> From time to time, just when I thought I knew my R, I get
>>> bitten by some
>> small things that reminds one to constantly return to the
>> basics.
> 
>> I knew for instance that "-1" < 0 is TRUE, presumably
>> because R first coerces to numeric before comparing with
>> 0.
> 
>> But I did not expect that "--" < 0 is a TRUE statement.
>> (and the same holds for any string prepended by a minus
>> sign, e.g. "-a" < 0)
> 
>> I would be grateful for an explanation, I'm sure that
>> something very obvious escapes me but it sure does seem
>> counter intuitive to me.
> 
>> Best wishes, Adrian
> 
>> 	[[alternative HTML version deleted]]
> 
> Nice, quiz, yes.
> 
> You must have forgotten that all Op's (+,-, <= , &, | ..)
> must coerce to common type.
> 
> ... and so does  c()  where coercion is defined a bit more.
> 
> -->  does  c("--", 0)   give you a clue, now ?
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk  Priv: PDalgd using gmail.com



More information about the R-help mailing list