【发布时间】:2012-02-27 22:15:07
【问题描述】:
我有一个 xts 数字矩阵,我需要在其上应用许多转换。根据thread,transform() 返回的对象应该包含在对 as.xts() 的调用中(xts 没有自己的转换版本,zoo 返回一个新对象)。
我已经尝试在一些示例数据上进行转换,它似乎工作正常,但是当我在我自己的数据上运行它时,我收到了这个错误:
Browse[2]> class(myxts)
[1] "xts" "zoo"
Browse[2]> mode(myxts)
[1] "numeric"
Browse[2]> str(myxts)
An 'xts' object from 2011-07-22 09:30:00 to 2011-12-19 16:00:00 containing:
Data: num [1:11606, 1:19] 0 158300 157700 157600 157900 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:19] "Open" "High" "Low" "Close" ...
Indexed by objects of class: [POSIXlt,POSIXt] TZ:
xts Attributes:
NULL
Browse[2]> head(myxts['2011-07-22'])
Open High Low Close
2011-07-22 09:30:00 0 0 0 0
2011-07-22 09:31:00 158300 158400 157600 157800
2011-07-22 09:32:00 157700 157700 157500 157700
2011-07-22 09:33:00 157600 157900 157599 157900
2011-07-22 09:34:00 157900 158100 157800 158100
2011-07-22 09:35:00 158000 158400 157900 158200
Browse[2]> n
debug: myxts = as.xts(transform(myxts, Open = ifelse(Open ==
0, NA, Open), Close = ifelse(Close == 0, NA, Close), High = ifelse(High ==
0, NA, High), Low = ifelse(Low == 0, NA, Low)))
Browse[2]> class(myxts)
[1] "xts" "zoo"
Browse[2]> head(myxts['2011-07-22'])
Error in function (year = 1970, month = 1, day = 1, hour = 0, min = 0, :
unused argument(s) (tz1 = "", tz2 = "EST", tz3 = "EDT")
Browse[2]> str(myxts)
An 'xts' object from 2011-07-22 09:30:00 to 2011-12-19 16:00:00 containing:
Data: num [1:11606, 1:19] NA 158300 157700 157600 157900 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:19] "Open" "High" "Low" "Close" ...
Indexed by objects of class: [POSIXlt,POSIXt] TZ:
TZ: EST
TZ: EDT
xts Attributes:
NULL
注意
在调用 transform() 后,str(myxts) 的输出中添加了 2 个 TZ: EST/EDT 字段。
【问题讨论】: