[R] Boundary problem
David Winsemius
dwinsemius at comcast.net
Wed Feb 3 13:19:16 CET 2010
On Feb 3, 2010, at 6:25 AM, Martin Kappler wrote:
> Hello,
>
> I have to vectors high and low on a time scale as follows
> time <- 1:5
> low <- c(1, 2, 3, 4, 5)
> high <- c(5, 4, 3, 4, 4)
>
> Now I'm searching for an elegant solution to know if a data point in
> time is
> inside the boundaries but not only on the predefined time points but
> continuous (e.g. time=2.5). For this the boundary points should be
> interpolated linearly.
>
> InBoundaries(t=2, y=1) => FALSE (too low)
> InBoundaries(t=2, y=2) => TRUE (on lower boundary)
> InBoundaries(t=2.5, y=3) => TRUE (between interpolation lines)
> InBoundaries(t=2.5, y=3.5) => TRUE (on upper interpolation line
> InBoundaries(t=2.5, y=3.51) => FALSE (above upper interpolation line)
?approxfun
lowaprx <- approxfun(low)
hiaprx <- approxfun(high)
> InBoundaries <- function(t,y) y >= lowaprx(t) & y <= hiaprx(t)
> InBoundaries(2,1)
[1] FALSE
> InBoundaries(2,2)
[1] TRUE
> InBoundaries(t=2.5, y=3) ; InBoundaries(t=2.5, y=3.5)
[1] TRUE
[1] TRUE
> InBoundaries(t=2.5, y=3.51)
[1] FALSE
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list