"hadley wickham" <[EMAIL PROTECTED]> writes:

> > As Peter said, it's the value that counts, not the way you calculated
> > it.  If you print -c(2,3,5) you get three negative numbers.  If you
> > print -integer(0), you don't get any.  The first case is asking for
> > elements to be left out, the second isn't.
> >
> > The moral of the story is to use logical indices rather than negative ones:
> >
> > dubious.records <- peoples.heights$heights > 2.5
> > peoples.heights = peoples.heights[!dubious.records,]
> 
> Unfortunately, there are some "matching" functions that return numeric
> indices, not logical vectors (eg. grep).  For this case I created an
> "unwhich" function - but is there a better way to proceed?

How about 

negIndex <- function(x) if (length(x)) -x else TRUE
> x <- 1:10
> x[negIndex(which(x>4))]
[1] 1 2 3 4
> x[negIndex(which(x>11))]
 [1]  1  2  3  4  5  6  7  8  9 10

Of course in this case, you can just avoid the which() bit entirely
and do

> x[!(x>4)]
[1] 1 2 3 4
> x[!(x>11)]
 [1]  1  2  3  4  5  6  7  8  9 10


-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])                  FAX: (+45) 35327907

______________________________________________
[email protected] mailing list
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.

Reply via email to