Skip to content

multivariate zoo and looping

2 messages · zubin, Gabor Grothendieck

#
Please try to provide reproducible code. That means that
one can simply copy it from the post and paste it into their
browser to rerun it and it has no dependencies. See last
line to every message to r-help.

If the question is how to get a zoo object from a data frame
then try this:

# create DF, a test data frame

Lines <- "ticker,time,open,bid
LQD,2009-09-10 10:39:00,104.99,104.96
LQD,2009-09-10 10:39:00,104.99,104.96
LQD,2009-09-10 10:40:00,104.99,104.96
LQD,2009-09-10 10:41:00,104.99,104.96
LQD,2009-09-10 10:42:00,104.99,104.98
LQD,2009-09-10 10:43:00,104.99,104.96"

DF <- read.csv(textConnection(Lines),  header = TRUE, as.is = TRUE)
DF$time <- as.POSIXct(DF$time)

# aggregate duplicate times
DFag <- aggregate(DF[3:4], DF["time"], mean)

#  convert to zoo
library(zoo)
z <- zoo(DFag[-1], DFag$time)
On Sun, Sep 13, 2009 at 10:09 AM, zubin <binabina at bellsouth.net> wrote: