Skip to content
Prev 138276 / 398506 Next

Formating a zoo dataset .

Your code below changes the class of the time index from "Date" to "character".
Perhaps you want "yearmon" class.  The following averages all values in
each month producing a series with time class "yearmon".  See ?yearmon

library(zoo)
z <- zoo(c(0.1423065, -0.03276228, -0.0652789, -0.04999873,
-0.01447902, 0.22265729), as.Date(c(11047, 11075, 11108,
11138, 11169, 11200)))
z
aggregate(z, as.yearmon, mean)

# Its also possible, though normally undesirable, to use "character" as your
# index class but then for it to make sense you will need to choose a
# representation which sorts appropriately under the usual rules for sorting:

aggregate(z, format(time(z), "%Y-%m"), mean)
On Mon, Mar 3, 2008 at 2:13 AM, Megh Dal <megh700004 at yahoo.com> wrote: