[R] Two similar zoo objects with different structures, how to get same structure?

Sergey Goriatchev sergeyg at gmail.com
Wed Jan 21 15:32:01 CET 2009


Dear all,

I have a zoo object that has following structure:

> str(bldata)
 zoo [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ...
 - attr(*, "index")=Classes 'dates', 'times'  atomic [1:5219] 7305
7306 7307 7308 7309 ...
  .. ..- attr(*, "format")= chr "m/d/y"
  .. ..- attr(*, "origin")= Named num [1:3] 1 1 1970
  .. .. ..- attr(*, "names")= chr [1:3] "month" "day" "year"
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:12] "ED4 COMDTY" "ED12 COMDTY" "ER4 COMDTY" "ER12 COMDTY" ...

I also have a vector of dates of same length as zoo object (5219):

> str(bldates)
 chr [1:5219] "01/01/90" "01/02/90" "01/03/90" "01/04/90" "01/05/90"
"01/08/90" "01/09/90" "01/10/90" "01/11/90" "01/12/90" ...

I do the following:

> attributes(bldata)[[2]] <- as.Date(bldates, "%m/%d/%y")

and get the following:

> str(bldata)
'zoo' series from 1990-01-01 to 2009-12-31
  Data: num [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:12] "ED4 COMDTY" "ED12 COMDTY" "ER4 COMDTY" "ER12 COMDTY" ...
  Index: Class 'Date'  num [1:5219] 7305 7306 7307 7308 7309 ...

But what I really want to get is the following:

>str(bldata)
'zoo' series from 01/01/90 to 12/31/09
  Data: num [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:12] "ED4 COMDTY" "ED12 COMDTY" "ER4 COMDTY" "ER12 COMDTY" ...
  Index: Classes 'dates', 'times'  atomic [1:5219] 7305 7306 7307 7308 7309 ...
  ..- attr(*, "format")= chr "m/d/y"
  ..- attr(*, "origin")= Named num [1:3] 1 1 1970
  .. ..- attr(*, "names")= chr [1:3] "month" "day" "year"

The array bldata is the same, only the last one is on a machine
running RBloomberg, and then I tried to save bldata (and rownames of
bldata in bldates) and
transfer bldata to the other machine which is not a Bloomberg
terminal, and the structure of bldata changes.

What should I do in this case to adjust the structure? I guess I have
to somehow change the class of Index and set attributes of "Index" and
attribute "names" of attribute "origin" of attribute "Index"?

Thank you for your help in advance!

Regards,
Sergey

-- 
I'm not young enough to know everything. /Oscar Wilde
Experience is one thing you can't get for nothing. /Oscar Wilde
When you are finished changing, you're finished. /Benjamin Franklin
Tell me and I forget, teach me and I remember, involve me and I learn.
/Benjamin Franklin
Luck is where preparation meets opportunity. /George Patten




More information about the R-help mailing list