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, <[EMAIL PROTECTED]> wrote: > 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 > >> t1 = zoo (matrix (1:12, nrow = 3), order.by = as.Date > (c("2008-08-01","2008-08-02","2008-08-03"))) >> colnames (t1) = c ("A", "B", "C", "D") >> t2 = zoo (matrix (1:12, nrow = 3), order.by = as.Date > (c("2008-08-02","2008-08-03","2008-08-04"))) >> colnames (t2) = c ("B", "C", "D", "E") > >> both.dates = as.Date (intersect (index (t1), index (t2))) >> both.cols = intersect (colnames (t1), colnames (t2)) > > Then calling >> t1 [both.dates, both.cols] > gives the expected > B C D > 2008-08-02 5 8 11 > 2008-08-03 6 9 12 > > And >> t2 [both.dates, both.cols] > gives > B C D > 2008-08-02 1 4 7 > 2008-08-03 2 5 8 > > But >> t1 [both.dates, both.cols] <- t2 [both.dates, both.cols] > 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 > >> t1 [as.Date (both.dates), both.cols] = matrix (1, nrow = 2, ncol = 3) > 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. > > (c) 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. > > > ______________________________________________ > R-help@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. > > ______________________________________________ R-help@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.