【发布时间】:2021-02-03 09:55:38
【问题描述】:
我正在使用 R。我有一组值和一个日期时间索引。我想在 xts 中转换 tibble。
这里是示例数据和我使用的代码:
Date <- c("2010-01-04" , "2010-01-04")
Time <- c("04:00:00", "06:00:00")
value <- c(1, 2)
df <- as_tibble(value) %>% add_column(Date = Date, Time = Time)
df <- df %>% mutate(datetime = as.POSIXct(paste(Date, Time), format="%Y-%m-%d %H:%M:%S"))
library(xts)
dfxts <- as.xts(df[,1], order.by=df[,4])
但是,我收到以下错误:
Error in xts(x, order.by = order.by, frequency = frequency, ...) :
order.by requires an appropriate time-based object
知道是什么原因造成的吗?日期时间应该是一个合适的基于时间的对象...非常感谢。
【问题讨论】: