Re: [R] negative indexing with null index sets

2008-06-05 Thread Gabor Grothendieck
Here are a few possibilities. The first three use seq_along and the last two use if and length: x[ !seq_along(x) %in% a[s] ] x[ !match(seq_along(x), a[s], 0) ] x[ setdiff(seq_along(x), a[s]) ] if (length(a[s])) x[-a[s]] else x x[ if (length(a[s])) -a[s] else TRUE ] On Thu, Jun 5, 2008 at 3:

[R] negative indexing with null index sets

2008-06-05 Thread roger koenker
Negative indexing is often handy, but I'm in need of an appropriate idiom for handling cases in which the index set can be null: x <- rnorm(5) a <- 1:5 s <- rep(FALSE,5) y <- x[-a[s]] # I'd like y == x but instead one has x[-a[s]] == x[a[s]] == numeric(0), which is rather # unfortunate -