[R] ZOO: Learning to apply it to my data

Rich Shepard rshepard at appl-ecosys.com
Wed Sep 14 02:21:05 CEST 2011


On Tue, 13 Sep 2011, Gabor Grothendieck wrote:

> In the example data there were no duplicate dates for a given param value.

Gabor,

   There are duplicate dates for a given param value, but each is on a
different stream. It is the triplet (stream, sampdate, param) that is
associated with each value (quant).

> 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

   I think this is what I want. :-) Let me ponder it and respond tomorrow
after I play with it to understand what's being done.

Many thanks,

Rich



More information about the R-help mailing list