[R] interpolation issue
Petr Savicky
savicky at cs.cas.cz
Wed Apr 18 23:09:54 CEST 2012
On Wed, Apr 18, 2012 at 07:15:45AM -0700, uday wrote:
> hi Petr ,
> Thanks for replay and sorry for typo mistake
> approx(pres, sci.pre) its nothing but approx(pre2, pre1).
>
> so for more simplicity
> x <- c(10.34615 , 52.02116, 146.17357, 243.28644, 347.41504, 431.67105,
> 521.42712, 629.00446 ,729.95941, 827.86279, 921.55078,
> 956.44446)
> y <- c( 983.4477692, 973.6199013, 958.0722141, 938.8194208 ,915.1833983,
> 852.1671089,
> 765.0037479,654.0372907, 526.7369169, 397.0581990, 279.9788079,
> 229.5127059,
> 185.2578164 ,147.2534510,115.1949457, 88.5712513, 66.7337287,
> 49.0140828,
> 23.3535195 , 0.6609724)
> approx(x,y,xout=x,method="linear")
> still I get error message
> Error in xy.coords(x, y) : 'x' and 'y' lengths differ
>
> I saw the approx. function , but yet I do not know that how we can use that
> for the data set which having different length
Hi.
Try to explain, what do you want to compute.
A typical use of approx() needs three vectors. The first two have the
same length and define a few points of a function, say f(x). The third
vector is called "xout" and may have an arbitrary length.
approx(x, y, xout) then computes an approximation of f() evaluated in
the components of "xout". For, example
x <- 1:4
y <- (1:4)^2
plot(x, y)
xout <- runif(20, min=1, max=4)
out <- approx(x=x, y=y, xout=xout)
points(xout, out$y, pch=20)
What do you want to compute, if you have only two vectors?
Petr Savicky.
More information about the R-help
mailing list