[R] making zoo objects with zoo without format argument?

Gabor Grothendieck ggrothendieck at gmail.com
Tue Jul 8 20:55:28 CEST 2008


On Tue, Jul 8, 2008 at 2:43 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> There is no data in your data frame, just index info, so I assume you
> want a zero width time series:
>
> zoo(, as.yearmon(x$Yearmonth, "%Y-%m"))
>
> This also works but then you are left with a character date which you
> may not want:
>
> zoo(, x$Yearmonth)

This last one should have been:

zoo(, as.character(x$Yearmon))

since your data frame holds a factor rather than character column.


>
>
> On Tue, Jul 8, 2008 at 1:43 PM, stephen sefick <ssefick at gmail.com> wrote:
>> #this is a subset of a larger data frame and I am okay with subsetting it as
>> there are redundant time stamps, but I would like to create a zoo object out
>> of this and I am having a hard #time figuring out how to do this  the date
>> structure is  year and then month
>>
>> x <- structure(list(Yearmonth = structure(c(12L, 24L, 1L, 13L, 14L,
>> 3L, 15L, 4L, 16L, 5L, 17L, 6L, 18L, 7L, 19L, 8L, 20L, 9L, 21L,
>> 10L, 22L, 11L, 23L), .Label = c("2006-02", "2006-03", "2006-04",
>> "2006-05", "2006-06", "2006-07", "2006-08", "2006-09", "2006-10",
>> "2006-11", "2006-12", "2007-01", "2007-02", "2007-03", "2007-04",
>> "2007-05", "2007-06", "2007-07", "2007-08", "2007-09", "2007-10",
>> "2007-11", "2007-12", "2008-01"), class = "factor"), Month = c(1L,
>> 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L,
>> 10L, 10L, 11L, 11L, 12L, 12L)), .Names = c("Yearmonth", "Month"
>> ), class = "data.frame", row.names = c(NA, 23L))
>>
>> #thanks Stephen
>>
>> --
>> Let's not spend our time and resources thinking about things that are so
>> little or so large that all they really do for us is puff us up and make us
>> feel like gods. We are mammals, and have not exhausted the annoying little
>> problems of being mammals.
>>
>> -K. Mullis
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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