[R] Odd behaviour of removing 'nothing' from an array or data frame
hadley wickham
h.wickham at gmail.com
Tue Oct 31 17:07:00 CET 2006
> 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?
Hadley
More information about the R-help
mailing list