ce
2014-Jan-17 01:32 UTC
[R] xts error: number of items to replace is not a multiple of replacement length
Dear all , I am getting this error while trying to change columns of an xts object with a date range as index.> library(xts)Loading required package: zoo Attaching package: ?zoo? The following object is masked from ?package:base?: as.Date, as.Date.numeric> data(sample_matrix) > sample.xts <- as.xts(sample_matrix, descr='my new xts object') > head(sample.xts)Open High Low Close 2007-01-02 50.03978 50.11778 49.95041 50.11778 2007-01-03 50.23050 50.42188 50.23050 50.39767 2007-01-04 50.42096 50.42096 50.26414 50.33236 2007-01-05 50.37347 50.37347 50.22103 50.33459 2007-01-06 50.24433 50.24433 50.11121 50.18112 2007-01-07 50.13211 50.21561 49.99185 49.99185> > sample.xts$Close <- sample.xts$Close+1 > > head(sample.xts)Open High Low Close 2007-01-02 50.03978 50.11778 49.95041 51.11778 2007-01-03 50.23050 50.42188 50.23050 51.39767 2007-01-04 50.42096 50.42096 50.26414 51.33236 2007-01-05 50.37347 50.37347 50.22103 51.33459 2007-01-06 50.24433 50.24433 50.11121 51.18112 2007-01-07 50.13211 50.21561 49.99185 50.99185> > sample.xts["2007-01-02::2007-01-04"]Open High Low Close 2007-01-02 50.03978 50.11778 49.95041 51.11778 2007-01-03 50.23050 50.42188 50.23050 51.39767 2007-01-04 50.42096 50.42096 50.26414 51.33236> > sample.xts["2007-01-02::2007-01-04"]$Close <- sample.xts["2007-01-02::2007-01-04"]$Close+1Warning message: In NextMethod(.Generic) : number of items to replace is not a multiple of replacement length
arun
2014-Jan-17 01:42 UTC
[R] xts error: number of items to replace is not a multiple of replacement length
Hi, Try: sample.xts["2007-01-02::2007-01-04","Close"] <-sample.xts["2007-01-02::2007-01-04","Close"] +1 sample.xts["2007-01-02::2007-01-04"] #?????????????? Open???? High????? Low??? Close #2007-01-02 50.03978 50.11778 49.95041 52.11778 #2007-01-03 50.23050 50.42188 50.23050 52.39767 #2007-01-04 50.42096 50.42096 50.26414 52.33236 A.K. On Thursday, January 16, 2014 8:34 PM, ce <zadig_1 at excite.com> wrote: Dear all , I am getting this error while trying to change columns of an xts object with a date range as index.> library(xts)Loading required package: zoo Attaching package: ?zoo? The following object is masked from ?package:base?: ? ? as.Date, as.Date.numeric>? ? ? data(sample_matrix) >? ? ? sample.xts <- as.xts(sample_matrix, descr='my new xts object') > head(sample.xts)? ? ? ? ? ? ? Open? ? High? ? ? Low? ? Close 2007-01-02 50.03978 50.11778 49.95041 50.11778 2007-01-03 50.23050 50.42188 50.23050 50.39767 2007-01-04 50.42096 50.42096 50.26414 50.33236 2007-01-05 50.37347 50.37347 50.22103 50.33459 2007-01-06 50.24433 50.24433 50.11121 50.18112 2007-01-07 50.13211 50.21561 49.99185 49.99185? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?> > sample.xts$Close <- sample.xts$Close+1 > > head(sample.xts)? ? ? ? ? ? ? Open? ? High? ? ? Low? ? Close 2007-01-02 50.03978 50.11778 49.95041 51.11778 2007-01-03 50.23050 50.42188 50.23050 51.39767 2007-01-04 50.42096 50.42096 50.26414 51.33236 2007-01-05 50.37347 50.37347 50.22103 51.33459 2007-01-06 50.24433 50.24433 50.11121 51.18112 2007-01-07 50.13211 50.21561 49.99185 50.99185> > sample.xts["2007-01-02::2007-01-04"]? ? ? ? ? ? ? Open? ? High? ? ? Low? ? Close 2007-01-02 50.03978 50.11778 49.95041 51.11778 2007-01-03 50.23050 50.42188 50.23050 51.39767 2007-01-04 50.42096 50.42096 50.26414 51.33236> > sample.xts["2007-01-02::2007-01-04"]$Close <- sample.xts["2007-01-02::2007-01-04"]$Close+1Warning message: In NextMethod(.Generic) : ? number of items to replace is not a multiple of replacement length ______________________________________________ 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.