stephen sefick
2008-Jul-28 00:12 UTC
[R] Interpolating a line and then summing there values for a diurnal oxygen curve (zoo object)
#I would like to interpolate a straight line between 06/08/06 04:16:00 - 06/08/06 20:31:00 with values and then sum them. This is an estimate of ecosystem #respiration and I will be using this in a larger context(48 days of these diurnal curves), but for right now I am just trying to figure out how to do it for this one #day example. I have some other code for Ecosystem (stream) Metabolism that I am trying to work up into a package, but I am still assembling the pieces. #thanks for all of your help library(chron) library(zoo) z <- structure(c(7.7, 7.7, 7.7, 7.7, 7.7, 7.71, 7.7, 7.71, 7.71, 7.7, 7.7, 7.7, 7.7, 7.69, 7.68, 7.68, 7.67, 7.67, 7.67, 7.66, 7.65, 7.65, 7.65, 7.64, 7.64, 7.63, 7.63, 7.63, 7.62, 7.62, 7.62, 7.62, 7.63, 7.63, 7.63, 7.63, 7.63, 7.64, 7.64, 7.65, 7.65, 7.65, 7.66, 7.66, 7.67, 7.67, 7.67, 7.68, 7.68, 7.69, 7.69, 7.69, 7.69, 7.7, 7.7, 7.7, 7.7, 7.7, 7.71, 7.7, 7.7, 7.71, 7.71, 7.7, 7.7, 7.7, 7.7, 7.7, 7.7, 7.7, 7.69, 7.68, 7.68, 7.68, 7.67, 7.67, 7.66, 7.66, 7.66, 7.66, 7.65, 7.65, 7.65, 7.65, 7.66, 7.66, 7.66, 7.67, 7.67, 7.68, 7.68, 7.68, 7.68, 7.69, 7.69, 7.69), index structure(c(13307.0006944444, 13307.0111111111, 13307.0215277778, 13307.0319444444, 13307.0423611111, 13307.0527777778, 13307.0631944444, 13307.0736111111, 13307.0840277778, 13307.0944444444, 13307.1048611111, 13307.1152777778, 13307.1256944444, 13307.1361111111, 13307.1465277778, 13307.1569444444, 13307.1673611111, 13307.1777777778, 13307.1881944444, 13307.1986111111, 13307.2090277778, 13307.2194444444, 13307.2298611111, 13307.2402777778, 13307.2506944444, 13307.2611111111, 13307.2715277778, 13307.2819444444, 13307.2923611111, 13307.3027777778, 13307.3131944444, 13307.3236111111, 13307.3340277778, 13307.3444444444, 13307.3548611111, 13307.3652777778, 13307.3756944444, 13307.3861111111, 13307.3965277778, 13307.4069444444, 13307.4173611111, 13307.4277777778, 13307.4381944444, 13307.4486111111, 13307.4590277778, 13307.4694444444, 13307.4798611111, 13307.4902777778, 13307.5006944444, 13307.5111111111, 13307.5215277778, 13307.5319444444, 13307.5423611111, 13307.5527777778, 13307.5631944444, 13307.5736111111, 13307.5840277778, 13307.5944444444, 13307.6048611111, 13307.6152777778, 13307.6256944444, 13307.6361111111, 13307.6465277778, 13307.6569444444, 13307.6673611111, 13307.6777777778, 13307.6881944444, 13307.6986111111, 13307.7090277778, 13307.7194444444, 13307.7298611111, 13307.7402777778, 13307.7506944444, 13307.7611111111, 13307.7715277778, 13307.7819444444, 13307.7923611111, 13307.8027777778, 13307.8131944444, 13307.8236111111, 13307.8340277778, 13307.8444444444, 13307.8548611111, 13307.8652777778, 13307.8756944444, 13307.8861111111, 13307.8965277778, 13307.9069444444, 13307.9173611111, 13307.9277777778, 13307.9381944444, 13307.9486111111, 13307.9590277778, 13307.9694444444, 13307.9798611111, 13307.9902777778), format structure(c("m/d/y", "h:m:s"), .Names = c("dates", "times")), origin = structure(c(1, 1, 1970), .Names = c("month", "day", "year")), class = c("chron", "dates", "times")), class = "zoo") plot(z) -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[alternative HTML version deleted]]
Gabor Grothendieck
2008-Jul-28 00:48 UTC
[R] Interpolating a line and then summing there values for a diurnal oxygen curve (zoo object)
Try this using your z and library(zoo): # extract section of interest w <- window(z, start=chron("6/8/6", "4:16:0"), end=chron("6/8/6", "20:31:0")) # zap all interior points with NA's and then fill back in using linear interpolation lin <- na.approx(replace(w, time(w) > start(w) & time(w) < end(w), NA)) # plot the 3 series on one screen plot(merge(z, w, lin), col = 1:3, screen = 1) On Sun, Jul 27, 2008 at 8:12 PM, stephen sefick <ssefick at gmail.com> wrote:> #I would like to interpolate a straight line between 06/08/06 04:16:00 - > 06/08/06 20:31:00 with values and then sum them. This is an estimate of > ecosystem #respiration and I will be using this in a larger context(48 days > of these diurnal curves), but for right now I am just trying to figure out > how to do it for this one #day example. I have some other code for > Ecosystem (stream) Metabolism that I am trying to work up into a package, > but I am still assembling the pieces. > #thanks for all of your help > > library(chron) > library(zoo) > z <- structure(c(7.7, 7.7, 7.7, 7.7, 7.7, 7.71, 7.7, 7.71, 7.71, 7.7, > 7.7, 7.7, 7.7, 7.69, 7.68, 7.68, 7.67, 7.67, 7.67, 7.66, 7.65, > 7.65, 7.65, 7.64, 7.64, 7.63, 7.63, 7.63, 7.62, 7.62, 7.62, 7.62, > 7.63, 7.63, 7.63, 7.63, 7.63, 7.64, 7.64, 7.65, 7.65, 7.65, 7.66, > 7.66, 7.67, 7.67, 7.67, 7.68, 7.68, 7.69, 7.69, 7.69, 7.69, 7.7, > 7.7, 7.7, 7.7, 7.7, 7.71, 7.7, 7.7, 7.71, 7.71, 7.7, 7.7, 7.7, > 7.7, 7.7, 7.7, 7.7, 7.69, 7.68, 7.68, 7.68, 7.67, 7.67, 7.66, > 7.66, 7.66, 7.66, 7.65, 7.65, 7.65, 7.65, 7.66, 7.66, 7.66, 7.67, > 7.67, 7.68, 7.68, 7.68, 7.68, 7.69, 7.69, 7.69), index > structure(c(13307.0006944444, > 13307.0111111111, 13307.0215277778, 13307.0319444444, 13307.0423611111, > 13307.0527777778, 13307.0631944444, 13307.0736111111, 13307.0840277778, > 13307.0944444444, 13307.1048611111, 13307.1152777778, 13307.1256944444, > 13307.1361111111, 13307.1465277778, 13307.1569444444, 13307.1673611111, > 13307.1777777778, 13307.1881944444, 13307.1986111111, 13307.2090277778, > 13307.2194444444, 13307.2298611111, 13307.2402777778, 13307.2506944444, > 13307.2611111111, 13307.2715277778, 13307.2819444444, 13307.2923611111, > 13307.3027777778, 13307.3131944444, 13307.3236111111, 13307.3340277778, > 13307.3444444444, 13307.3548611111, 13307.3652777778, 13307.3756944444, > 13307.3861111111, 13307.3965277778, 13307.4069444444, 13307.4173611111, > 13307.4277777778, 13307.4381944444, 13307.4486111111, 13307.4590277778, > 13307.4694444444, 13307.4798611111, 13307.4902777778, 13307.5006944444, > 13307.5111111111, 13307.5215277778, 13307.5319444444, 13307.5423611111, > 13307.5527777778, 13307.5631944444, 13307.5736111111, 13307.5840277778, > 13307.5944444444, 13307.6048611111, 13307.6152777778, 13307.6256944444, > 13307.6361111111, 13307.6465277778, 13307.6569444444, 13307.6673611111, > 13307.6777777778, 13307.6881944444, 13307.6986111111, 13307.7090277778, > 13307.7194444444, 13307.7298611111, 13307.7402777778, 13307.7506944444, > 13307.7611111111, 13307.7715277778, 13307.7819444444, 13307.7923611111, > 13307.8027777778, 13307.8131944444, 13307.8236111111, 13307.8340277778, > 13307.8444444444, 13307.8548611111, 13307.8652777778, 13307.8756944444, > 13307.8861111111, 13307.8965277778, 13307.9069444444, 13307.9173611111, > 13307.9277777778, 13307.9381944444, 13307.9486111111, 13307.9590277778, > 13307.9694444444, 13307.9798611111, 13307.9902777778), format > structure(c("m/d/y", > "h:m:s"), .Names = c("dates", "times")), origin = structure(c(1, > 1, 1970), .Names = c("month", "day", "year")), class = c("chron", > "dates", "times")), class = "zoo") > plot(z) > > -- > Let's not spend our time and resources thinking about things that are so > little or so large that all they really do for us is puff us up and make us > feel like gods. We are mammals, and have not exhausted the annoying little > problems of being mammals. > > -K. Mullis > > [[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. >