我尝试导入外部外汇数据,但无法将其转换为xts对象

问题描述 投票:1回答:1

我试图将excel文件导入为xts对象,但我遇到了这条消息

字符串不是标准的明确格式

我尝试使用csv格式的外部数据文件,但它没有工作,似乎没有其他现有的答案能够解决我的问题

这是我的代码和结果

CNY <- read_excel("data/RAW.xlsx", sheet = "CNY") #Import external data
CNY
# A tibble: 9,845 x 2
X__1                 Line
<dttm>              <dbl>
 1 1981-01-02 00:00:00  1.53
 2 1981-01-05 00:00:00  1.54
 3 1981-01-06 00:00:00  1.53
 4 1981-01-07 00:00:00  1.53
 5 1981-01-08 00:00:00  1.53
 6 1981-01-09 00:00:00  1.54
 7 1981-01-12 00:00:00  1.54
 8 1981-01-13 00:00:00  1.54
 9 1981-01-14 00:00:00  1.54
10 1981-01-15 00:00:00  1.54
# ... with 9,835 more rows
CNY <- as.xts(CNY)

Error in as.POSIXlt.character(x, tz, ...) : 
character string is not in a standard unambiguous format

我希望CNY是一个xts对象,好像我使用了getSymbols函数

r import time-series xts import-from-excel
1个回答
0
投票

这有用吗?

myxts <- xts(CNY$Line, order.by = CNY$X__1)
© www.soinside.com 2019 - 2024. All rights reserved.