我正在尝试将刻度数据转换为分钟数据。
dolar_1min_xts <- xts()
print(dolar_for_manipulation_xts)
[1]
Price
2018-02-01 09:00:57 "3203.0"
2018-02-01 09:00:57 "3203.5"
2018-02-01 09:00:57 "3203.5"
2018-02-01 09:00:57 "3203.5"
2018-02-01 09:00:57 "3203.5"
2018-02-01 09:00:57 "3203.5"
[...]
dolar_1min_xts <- to.period(dolar_for_manipulation_xts, period = "minutes", k = 1)
to.period(dolar_for_manipulation_xts,period =“分钟”,:不支持的类型
我如何解决此问题的任何提示?
为了复制:
dolar_for_manipulation_xts
structure(c("3203.0", "3203.5", "3203.5", "3203.5", "3203.5",
"3203.5"), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
"POSIXt"), tclass = c("POSIXct", "POSIXt"), .indexTZ = "", tzone = "", index = structure(c(1517482857,
1517482857, 1517482857, 1517482857, 1517482857, 1517482857), tzone = "", tclass = c("POSIXct",
"POSIXt")), .Dim = c(6L, 1L), .Dimnames = list(NULL, "Price"))
答案 0 :(得分:1)
我在https://www.rdocumentation.org/packages/xts/versions/0.11-2/topics/to.period签出了文档
并运行示例代码
data(sample_matrix)
samplexts <- as.xts(sample_matrix)
to.monthly(samplexts)
str(samplexts)
An ‘xts’ object on 2007-01-02/2007-06-30 containing: Data: num [1:180, 1:4] 50 50.2 50.4 50.4 50.2 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:4] "Open" "High" "Low" "Close" Indexed by objects of class: [POSIXct,POSIXt] TZ: xts Attributes: NULL
并与您的数据进行比较
str(dolar_for_manipulation_xts)
An ‘xts’ object on 2018-02-01 06:00:57/2018-02-01 06:00:57 containing: Data: chr [1:6, 1] "3203.0" "3203.5" "3203.5" "3203.5" "3203.5" "3203.5" - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr "Price" Indexed by objects of class: [POSIXct,POSIXt] TZ: xts Attributes: NULL
并且注意到您的数据是chr(字符串),而不是num!
我通过删除数字周围的引号(“ 3203.0”)更改为数字,并且该功能正常运行。