Skip to content

why the a[-indx] does not work?

12 messages · Alaios, Duncan Murdoch, William Dunlap +3 more

#
On 11-10-30 2:52 PM, Alaios wrote:
You are asking it to remove item 1, and it does.  If you want to negate 
a logical vector, you need to use a logical vector and negate it, e.g.

OverloadsTesT <- as.logical(OverloadsTeSt)
a[!OverloadsTest]

Duncan Murdoch
#
[1]  2  4  5  6  7  8  9 10
Look into help('[') or help('Subscript') to see
how integer and logical (Boolean) subscripts differ.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
#
Duncan Murdoch-2 wrote:
Or:

a[-c(1,3)]
#
ifelse(myvec == 0, FALSE, TRUE) # set 0 to FALSE, other values to TRUE
On Sun, Oct 30, 2011 at 3:50 PM, Alaios <alaios at yahoo.com> wrote:
#
myvec != 0
does the same as
  ifelse(myvec == 0, FALSE, TRUE)
but more quickly

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
#
I like to use numericVector != 0 instead of
is.logical(numericVector) because the former
more directly indicates what you want to happen
instead of relying on knowledge that numeric 0
maps to logical FALSE.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com