[英]Error in plotting xts object: 'x' must be a time-series object
[英]i am getting double date and time column after using xts? and getting error 'x' must be a time-series object
我面臨一個問題。 我正在嘗試將我的數據轉換為 xts object 以便稍后我可以合並時間序列和 plot 它們。 但我收到錯誤“x”必須是時間序列 object。我將在此處顯示示例數據。
time<-c("21.11.2021 22:45", "21.11.2021 23:25")
time_p<-as.POSIXct(time, format='%d.%m.%Y %H:%M')
value1<-c(1,9)
value1<-as.numeric(value1)
value2<-c(1,21)
value2<-as.numeric(value2)
time_dataframe<-cbind.data.frame(time_p,value1,value2)
time_dataframe<-xts(time_dataframe,order.by(time_p)
但是當我 plot 時,我得到一個錯誤'x' must be a time-series。
而且我正在進入 output 2 次日期和時間列,如下所示。
time_p value 1 value 2
2021-11-21 22:45:00 2021-11-21 22:45:00 1 1
2021-11-21 23:25:00 2021-11-21 23:25:00 9 21
數據部分不應包括時間。
library(xts)
time <- c("21.11.2021 22:45", "21.11.2021 23:25")
time_p <- as.POSIXct(time, format='%d.%m.%Y %H:%M')
value1 <- c(1, 9)
value2 <- c(1, 21)
xts(cbind(value1, value2), time_p)
## value1 value2
## 2021-11-21 22:45:00 1 1
## 2021-11-21 23:25:00 9 21
或者
DF <- data.frame(time_p, value1, value2)
z <- read.zoo(DF)
as.xts(z)
# same
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.