Thanks Sarah,
Yes, the function behaves Exactly as documented:
check this out:
> a = c(1,2,3,4,5)
> a[which(a!=6)]
[1] 1 2 3 4 5
> a[!which(a==6)]
numeric(0)
> a[-which(a==6)]
numeric(0)
> a[!a==6]
[1] 1 2 3 4 5
I guess this is just a "gotcha", since
I often use !which and -which to remove elem
If by "bug" you mean "function behaving exactly as documented."
which() returns only the matches, the TRUE values. If there are no
matches, it doesn't return anything.
If I understand what you are trying to do, and I may not,
a[which(a != 5)]
is really what you want, and it is precisely to preser
I think your rewrite is overdue, because returning the array from the which
function seems counterintuitive.
---
Jeff Newmiller The . . Go Live...
DCN: Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Res
Dear all,
I found a bug in the which() function.
When trying to remove elements with the which function,
if the criteria is not matched, numeric(0) is returned instead of the
array itself.
This is very weird.
> a = c(1,2,3,4,5)
> a[!a==6]
[1] 1 2 3 4 5
> a[-which(a==6)]
numeric(0)
> a[-which(a=
4 matches
Mail list logo