[R] Find a particular point on a curve
David Winsemius
dwinsemius at comcast.net
Fri Oct 7 23:36:38 CEST 2011
On Oct 7, 2011, at 5:06 PM, Joanie wrote:
> Here is a sample of my data:
>
> time temperature
> 40717.0140390 37.5
> 40717.0140510 37.5
>
> 40717.0519680 37.6
> 40717.0519790 37.6
> 40717.0520020 37.6
> 40717.0520140 37.6
After making that data into a dataframe named "dat"
> plot(dat)
> min(which(dat$temperature <37.5))
[1] 72
> max(which(dat$temperature >37.5))
[1] 2146
> dat$time[ max(which(dat$temperature >37.5)) ]
[1] 40717.05
> dat$time[ min(which(dat$temperature <37.5)) ]
[1] 40717.02
> dat$time[ max(which(dat$temperature >37.5)) ]-dat
$time[ min(which(dat$temperature <37.5)) ]
[1] 0.036644
> sum(dat$temperature - 37.5)
[1] -441.2
> # Units = degree-what .... minute? hours?, days?
> sum(dat$temperature - 37.5)*(dat$time[ max(which(dat$temperature
>37.5)) ]-dat$time[ min(which(dat$temperature <37.5)) ])
[1] -16.16733
So the area under the curve is -16.16 degree-<some-time-units>
(probably days)
You did not include the first request, which was something about the
duration of time that the temperature was at the minimum value (there
being no real plateau). Noting that the minumum (read off the plot)
was 36.7) I find:
> 60*24*(dat$time[ max(which(dat$temperature==36.7)) ]-dat
$time[ which.min(dat$temperature) ])
[1] 1.65024 # minutes (I think) spend at the nadir of temperature
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list