Skip to content
Prev 276163 / 398506 Next

why the a[-indx] does not work?

Er... you need to be (a lot) more careful with operator precendence. See ?Syntax for operator precedence.

-numericVector==0
will usually* give the same answer as 
numericVector==0

because unary minus has higher precedence than ==, so this is read implicitly as (-numericvector)==0. -1 and 1 are still both nozero, while -0 and 0 are both still zero. ( *'usually' because you may be comparing a double precision nearly-zero with another double precision nearly-zero, and that is _always_ asking for trouble.)

!numericVector==0 
behaves quite differently because unary negation (!, or NOT) has _lower_ precedence than ==, so this one is read as
!(numericVector==0)


Operatopr preference rules for programmers:
Rule 1: If in doubt about operator precedence, use parentheses
Rule 2: Always have doubts about operator precedence unless you have looked it up for _that_ version of _that_  language _that day_.
Rule 3: Check the operator precedence of parentheses.

S Ellison

*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
Message-ID: <A4E5A0B016B8CB41A485FC629B633CED37154E8F0C@GOLD.corp.lgc-group.com>
In-Reply-To: <1320008969.30713.YahooMailNeo@web120115.mail.ne1.yahoo.com>