Message-ID: <A4E5A0B016B8CB41A485FC629B633CED4A33957460@GOLD.corp.lgc-group.com>
Date: 2013-03-18T16:16:03Z
From: S Ellison
Subject: Counting confidence intervals
In-Reply-To: <CAKL8G3HL2qGOVktG3SAMYHmf2uBaZcWf7O=3aUNLGc+bLCQ9Vw@mail.gmail.com>
> > I want to cont how many
> > times a number say 12 lies in the interval. Can anyone assist?
Has anyone else ever wished there was a moderately general 'inside' or 'within' function in R for this problem?
For example, something that behaves more or less like
within <- function(x, interval=NULL, closed=c(TRUE, TRUE), lower=min(interval), upper=max(interval)) {
#interval must be a length 2 vector
#closed is taken in the order (lower, upper)
#lower and upper may be vectors and will be recycled (by "<" etc) if not of length length(x)
low.comp <- if(closed[1]) "<=" else "<"
high.comp <- if(closed[2]) ">=" else ">"
do.call(low.comp, list(lower, x)) & do.call(high.comp, list(upper, x))
}
#Examples
within(1:5, c(2,4))
within(1:5, c(2,4), closed=c(FALSE, TRUE))
within(1:5, lower=5:1, upper=10:14)
S Ellison
LGC
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}