[R] setting up zoo objects from a data frame
Stefan Grosse
singularitaet at gmx.net
Tue Jun 8 17:20:47 CEST 2010
Am 08.06.2010 16:52, schrieb Erin Hodgess:
>
> I would like to set up 3 time series; one for dog, one for cat, one
> for tree, such that each runs from 1/1/2000 to 1/3/2000, with 0 if
> there is no entry for the day.
>
>
>
Before using zoo or zooreg you should transform your data.frame as such
as that you have one column for each time series you want to have
afterwards. have a look at
?reshape
to do so.
little example:
test<-data.frame(date=c("2001/01/01","2001/01/01","2001/01/02","2001/01/02"),animal=c("dog","cat","dog","cat"),data=1:4)
test.w<-reshape(test,idvar="date",timevar="animal",direction="wide")
test.w
then you can do the zoo stuff, e.g. with
?zooreg
if you have a "regular" series.
It will transform automatically into a multiple time series.
hth
Stefan
More information about the R-help
mailing list