[R] ZOO object colnames refering to Dates

Achim Zeileis Achim.Zeileis at uibk.ac.at
Thu Feb 11 11:04:22 CET 2010


On Thu, 11 Feb 2010, Research wrote:

> Hello,
>
> I have  large zoo objects (about 100 or more time series merged next to 
> eachother). Example:
>
>    X05.Oct.99 X05.Nov.99 X05.Dec.99 X05.Jan.00 X05.Feb.00 X05.Mar.00 
> X05.Apr.00 X05.May.00 X05.Jun.00
> [1,]     5649.3     5679.4     5679.4     5679.4     5679.4     5679.4 
> 5679.4     5679.4     5679.4
> [2,]     5682.7     5719.2     5719.2     5719.2     5719.2     5719.2 
> 5719.2     5719.2     5719.2
> [3,]     5697.5     5745.5     5745.5     5745.5     5745.5     5745.5 
> 5745.5     5745.5     5745.5
> [4,]     5723.9     5767.8     5767.8     5767.8     5767.8     5767.8 
> 5767.8     5767.8     5767.8
> [5,]     5782.1     5829.8     5829.8     5829.8     5829.8     5829.8 
> 5829.8     5829.8     5829.8
> [6,]     5815.0     5850.9     5850.9     5850.9     5850.9     5850.9 
> 5850.9     5850.9     5850.9
>>
>
> The column names contain dates, i.e.,  X05.Oct.99 stands for a time sequence 
> that was obtained on 05/10/1999. Each column is obtained  month + 1 from the 
> previous one.
>
> Is it possible to access these columns (time series data) via a for/next loop 
> (or a while) that uses dates i/o (i in 1:8) in the above example?
>
> Say: if month==Oct and year==1999 choose column X05.Oct.99 ...

You can switch back and forth between character representations and 
timedate representations using strptime() and format() along with 
formatting strings, e.g.,

R> strptime("X05.Oct.99", "X%d.%b.%y")
[1] "1999-10-05"

R> format(strptime("X05.Oct.99", "X%d.%b.%y"), "X%d.%b.%y")
[1] "X05.Oct.99"

R> 
format(strptime("X05.Oct.99", "X%d.%b.%y"), "%d/%m/%Y")
[1] "05/10/1999"

And so on. See

   Grothendieck G, Petzoldt T (2004). "R Help Desk: Date and Time
   Classes in R." R News, 4(1), 29­32.
   URL http://www.R-project.org/doc/Rnews/Rnews_2004-1.pdf

for more details.

I wonder why you have the time information in the columns rather than in 
the rows though... If your measurements on that day represent intra-day 
measurements, simply use some time/date class, e.g., POSIXct (or chron or 
timeDate) for that. If the measurements correspond to some replications 
they can just go into the columns rather than the rows of the series.

For examples in zoo, see the vignettes of the package.

hth,
Z

> Could I also generate automatically a variable, appropriately named from the 
> corresponding columns name that would contain the data and access it by that 
> date?
>
> Any pointers really appreciated.
>
> Thanks in advance,
> Costas
>
>
> __________ Information from ESET Smart Security, version of virus signature 
> database 4857 (20100211) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.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