Skip to content

A zoo question / problem

2 messages · david.jessop at ubs.com, Gabor Grothendieck

#
Hi

I'm having a problem using the zoo library and I can't see what I'm
doing wrong.  For example setting up the data
(c("2008-08-01","2008-08-02","2008-08-03")))
(c("2008-08-02","2008-08-03","2008-08-04")))
Then calling
gives the expected 
           B C  D
2008-08-02 5 8 11
2008-08-03 6 9 12

And
gives
           B C D
2008-08-02 1 4 7
2008-08-03 2 5 8

But
gives
Error in t1[both.dates, both.cols] <- t2[both.dates, both.cols] : 
 subscript out of bounds

I've tried various varieties of as.matrix, coredata but always get this
error. It's something to do with the first part of the expression as
Error in t1[as.Date(both.dates), both.cols] = matrix(1, nrow = 2, ncol =
3) : 
  subscript out of bounds 

So I'm stuck.  I'm running on Windows with R version 2.7.0

Regards,

David
Issued by UBS AG or affiliates to professional investors for 
information only and its accuracy/completeness is not guaranteed. 
All opinions may change without notice and may differ to 
opinions/recommendations expressed by other business areas of UBS. 
UBS may maintain long/short positions and trade in instruments 
referred to. Unless stated otherwise, this is not a personal 
recommendation, offer or solicitation to buy/sell and any 
prices/quotations are indicative only. UBS may provide investment 
banking and other services to, and/or its employees may be directors 
of, companies referred to. To the extent permitted by law, UBS does 
not accept any liability arising from the use of this communication.

 ? UBS 2008.  All rights reserved. Intended for recipient only
and not for further distribution without the consent of UBS.

UBS Limited is a company registered in England & Wales under company
number 2035362, whose registered office is at 1 Finsbury Avenue,
London, EC2M 2PP, United Kingdom.

UBS AG (London Branch) is registered as a branch of a foreign company
under number BR004507, whose registered office is at
1 Finsbury Avenue, London, EC2M 2PP, United Kingdom.

UBS Clearing and Execution Services Limited is a company registered
in England & Wales under company number 03123037, whose registered
office is at 1 Finsbury Avenue, London, EC2M 2PP, United Kingdom.
#
Even though there is a "[.zoo", there is no "[.zoo<-" in zoo.
For assignments it simply defaults to the ordinary [ for
vectors and matrices.   Any of these work:

window(t1, both.dates)[, both.cols] <- t2[both.dates, both.cols]

window(t1, both.dates)[, both.cols] <- window(t2, both.dates)[, both.cols]

t1[time(t1) %in% both.dates, both.cols] <- t2[both.dates, both.cols]

t1[time(t1) %in% both.dates, both.cols] <- t2[time(t2) %in%
both.dates, both.cols]
On Mon, Aug 11, 2008 at 5:59 AM, <david.jessop at ubs.com> wrote: