[R] xts error: number of items to replace is not a multiple of replacement length

ce zadig_1 at excite.com
Fri Jan 17 02:32:15 CET 2014


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+1
Warning message:
In NextMethod(.Generic) :
  number of items to replace is not a multiple of replacement length



More information about the R-help mailing list