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 -- so far the best I have come up with is:
as <- ifelse(length(a[s]),-a[s],TRUE)
y <- x[as]
which, doesn't read well. Apologies if this has been aired
previously...
url: www.econ.uiuc.edu/~roger Roger Koenker
email [EMAIL PROTECTED] Department of Economics
vox: 217-333-4558 University of Illinois
fax: 217-244-6678 Champaign, IL 61820
______________________________________________
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.