[R] [R[ dates on zoo objects
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Jun 10 15:58:15 CEST 2010
Its best to use dput when displaying your data in r-help as in dput(z)
or dput(head(z)) if large.
Try this:
> library(zoo)
> # test data
> z <- zoo(1:2, factor(c("04/16/09","04/17/09")))
>
> # 1
> aggregate(z, function(x) as.Date(x, "%m/%d/%y"))
2009-04-16 2009-04-17
1 2
>
> # or #2
> time(z) <- as.Date(time(z), "%m/%d/%y")
> z
2009-04-16 2009-04-17
1 2
On Thu, Jun 10, 2010 at 9:42 AM, Erin Hodgess <erinm.hodgess at gmail.com> wrote:
> Dear R People:
>
> I have a zoo object with its date index as a factor.
>
>> xAle1.zoo$index
> Error in xAle1.zoo$index : $ operator is invalid for atomic vectors
>> str(xAle1.zoo)
> Class 'zoo' atomic [1:32] 1253 1316 1038 1157 1710 1489 1159 1142 945 1245 ...
> ..- attr(*, "index")= Factor w/ 32 levels "04/16/09","04/17/09",..:
> 1 2 3 4 5 6 7 8 9 10 ...
>>
>
>
>
> How do I change that over to dates, please?
>
> Thanks,
> Erin
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodgess at gmail.com
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list