On Tue, Sep 13, 2011 at 7:36 PM, Rich Shepard <rshep...@appl-ecosys.com> wrote: > On Tue, 13 Sep 2011, Gabor Grothendieck wrote: > >> As in ?zoo a zoo object is a numeric matrix, numeric vector or factor >> together with an ordered time index which is unique. Its not clear that >> that is what you have; however, if we can assume that for each value of >> param we have a unique set of dates then quant could form a multivariate >> zoo series with Date index. > > Gabor, > > Perhaps, then, zoo is not the appropriate library for my needs. Let me try > to clarify; being new to R and certainly new to zoo I may not express myself > clearly to those of you who are more experienced. > > On a given date (sampdate) and a given stream (aggregated from multiple > locations on that stream) a water sample was sent to the laboratory and > analyzed for a set of chemicals (param). Each param does not have a unique > set of dates. As my example showed, on 2010-06-30 SO4, Zn, and As > concentrations were measured on Winters Creek. On 2011-06-06, Cl, SO4, and > Zn concentrations were measured on the same stream.
In the example data there were no duplicate dates for a given param value. If that is not true in general but it is true that there are no duplicate dates for each stream name/param combination then we could create a combined split field. (We also create a data frame DF first since you have indicated that a data frame is the input.) Lines <- "stream,sampdate,param,quant 11164 Winters,2010-06-30,SO4,120.000 11165 Winters,2010-06-30,Zn,0.010 11166 Winters,2011-06-06,As,0.005 11167 Winters,2011-06-06,Cl,5.000 11168 Winters,2011-06-06,SO4,150.000 11169 Winters,2011-06-06,Zn,0.010" DF <- read.csv(textConnection(Lines)) # strip number from stream field creating new split field # from stream name and param DF2 <- with(DF, data.frame( sampdate, date.param = paste(sub(".* ", "", stream), param), quant)) library(zoo) z <- read.zoo(DF2, split = 2) which gives: > z Winters As Winters Cl Winters SO4 Winters Zn 2010-06-30 NA NA 120 0.01 2011-06-06 0.005 5 150 0.01 -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@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.