Re: [R] Removing elements from a vector matching a criteria, BUG in which() function

2011-02-13 Thread Rumen Kostadinov
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

Re: [R] Removing elements from a vector matching a criteria, BUG in which() function

2011-02-13 Thread Sarah Goslee
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

Re: [R] Removing elements from a vector matching a criteria, BUG in which() function

2011-02-13 Thread Jeff Newmiller
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

[R] Removing elements from a vector matching a criteria, BUG in which() function

2011-02-13 Thread Rumen Kostadinov
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=