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==5)]
[1] 1 2 3 4
> a[!a==5]
[1] 1 2 3 4

Is this correct? I believe this is a bug.

I have to rewrite a lot of my R code to use
a = a[!criteria]
and not
a = a[-which(criteria)]

R.

______________________________________________
R-help@r-project.org 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