[R] Help on a code

Ista Zahn istazahn at gmail.com
Tue Feb 26 22:32:45 CET 2013


Hi Andras,

This may be too simplistic, but how about

with(Interpolated, x[y==2][1])

?


On Tue, Feb 26, 2013 at 4:21 PM, Andras Farkas <motyocska at yahoo.com> wrote:
> Dear List,
>
> I have the following code:
>
> x <-c(0, 13.8333333333333, 38.1666666666667, 62.1666666666667, 85.9166666666667, 108.916666666667)
> y <-c(1.77, 2.39, 3, 2.65, 2.62, 1.8)
> Interpolated <- approx(x, y,xout=0:tail(x, n=1),method="linear")
> plot(Interpolated)
>
> in this code x is time in hours (cumulative), and y is a biological variable. I am using linear interpolation assuming getting from y(i) to y(i+1) is a linear path. I would like to calculate the time in this case that it takes to surpass the y value of 2 for the first time. If you look at the plot, you will see that the y value of 2 is crossed on 2 occasions: between the first and second value of y (ie:1.77 to 2.39) and the fifth and sixth value of y (ie2.62 and 1.8). In my case I really only care about the first "section" (ie: how long it takes to get from 1.77 to 2.0). Any thoughts on how I could calculate that chunk of the time would be greatly appreciated.
>
> let me present it in a simpler idea wher I can actually tell you what the answer should be without having the code:
>
> x <-c(0, 12, 24, 36, 48, 60)
> y <-c(1.5, 2, 3, 2.65, 2.62, 1.8)
> Interpolated <- approx(x, y,xout=0:tail(x, n=1),method="linear")
> plot(Interpolated)
>
> the answer in this case is 12 hours, which is the time spent in getting from 1.5 to 2...
>
> hope I explained clearly what I am trying to do
>
> appreciate the help,
>
> Andras
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list