Hi:

Here's one approach, converting the sub-data frames to zoo objects:

# Function to convert one of the data frames to a zoo object
makezoo <- function(df) {
     require(zoo)
     date <- as.Date(df[, 1], format = '%m/%d/%y')
     with(df, zoo(freq, date))
    }
library(zoo)

# Split the data frame by condition:
tt <- split(x.df[, -2], x.df$cond)

# > str(tt[[1]])
# 'data.frame':   5 obs. of  2 variables:
#  $ date: Factor w/ 5 levels "04/01/09","04/02/09",..: 1 2 3 4 5
#  $ freq: int  12 11 10 13 6

# Apply the makezoo function to each component of the list tt:
(tser <- lapply(tt, makezoo))

$Fever
04/01/09 04/02/09 04/03/09 04/04/09 04/05/09
      12       11       10       13        6

$Rash
04/01/09 04/02/09 04/03/09 04/04/09 04/05/09
       6       10        9       10        8

$Respiratory
04/01/09 04/02/09 04/03/09 04/04/09 04/05/09
      12        9        6       11       11

# Check that the classes are OK:
> sapply(tser, class)
      Fever        Rash Respiratory
      "zoo"       "zoo"       "zoo"

You can then do things like plot.ts, for example:

lapply(tser, plot.ts)

HTH,
Dennis

On Wed, Jun 2, 2010 at 8:37 AM, Erin Hodgess <erinm.hodgess@gmail.com>wrote:

> Dear R People:
>
> I have the following data frame:
>
> > x.df
>       date        cond freq
> 1  04/01/09       Fever   12
> 2  04/02/09       Fever   11
> 3  04/03/09       Fever   10
> 4  04/04/09       Fever   13
> 5  04/05/09       Fever    6
> 6  04/01/09        Rash    6
> 7  04/02/09        Rash   10
> 8  04/03/09        Rash    9
> 9  04/04/09        Rash   10
> 10 04/05/09        Rash    8
> 11 04/01/09 Respiratory   12
> 12 04/02/09 Respiratory    9
> 13 04/03/09 Respiratory    6
> 14 04/04/09 Respiratory   11
> 15 04/05/09 Respiratory   11
> >
>
> I would like to generate 3 time series (or zoo objects or its); one
> for Fever, one for Rash, and one for Respiratory.   There are 2
> questions here, please:
> a. How do I generate the series, please?
> b. Which is best, time series, zoo objects, or its objects, please?
>
> Thanks,
> Erin
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodgess@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.
>

	[[alternative HTML version deleted]]

