Re: [R] how to get f(x)=___ from a piecwise function

From: jim holtman <jholtman_at_gmail.com>
Date: Sun 26 Feb 2006 - 16:27:48 EST

?approxfun

> x<- c(-100.4, 32.0, 99.8, 200.2, 300.6, 399.8, 500.0, 600.0, 699.6, 799.6,
+ 899.8)
> y<- c(0.4, 0.0, 0.2, -0.2, -0.6, 0.2, 0.0, 0.0, 0.4, 0.4, 0.2)
> x.f <- approxfun(x,y)
> x.f(356)

[1] -0.1532258

On 2/25/06, Eric C. Jennings <matheric@u.washington.edu> wrote:
>
> >From actual real-world readings, I have two vectors:
>
> x<- c(-100.4, 32.0, 99.8, 200.2, 300.6, 399.8, 500.0, 600.0, 699.6, 799.6,
> 899.8)
> y<- c(0.4, 0.0, 0.2, -0.2, -0.6, 0.2, 0.0, 0.0, 0.4, 0.4, 0.2)
>
> which, in the usual way constitute a continuous piecewise function.
>
> What I want to do is find an easy method to get at f(x) for some x I have
> NOT specified in the above vector. For example I want f(356).
>
> I have already put the time and effort in to write a program to compute
> this
> by breaking the function into the various pieces and computing the slopes
> of
> the individual lines etc. etc.
>
> I am just looking to find an easier method.
>
> Thank you for your help.
> Eric
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What the problem you are trying to solve?

	[[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sun Feb 26 16:39:09 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 24 Mar 2006 - 15:09:18 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.