我试图绘制以下每小时数据。如何将数据更改为时间序列对象?正在尝试使用xts
包但收到错误消息:
new_data <- structure(list(starttime = c("01.01.2015 00:00", "01.01.2015 01:00",
"01.01.2015 02:00", "01.01.2015 03:00", "01.01.2015 04:00", "01.01.2015 05:00"
), Fossil = c(435, 434, 435, 436, 436, 436)), .Names = c("starttime",
"Fossil"), row.names = c(NA, -6L), class = "data.frame")
str(new_data)
$ starttime: chr "01.01.2015 00:00" "01.01.2015 01:00" "01.01.2015 02:00" "01.01.2015 03:00" ...
$ Fossil : int 435 434 435 436 436 436 434 436 415 331
head(new_data)
starttime Fossil
1 01.01.2015 00:00 435
2 01.01.2015 01:00 434
3 01.01.2015 02:00 435
4 01.01.2015 03:00 436
5 01.01.2015 04:00 436
6 01.01.2015 05:00 436
hnew_dataxts <- as.xts(x=new_data[,"Fossil"], order.by=new_data[,"starttime"])
colenames(hnew_dataxts) <- colnames(new_data)[-1]
Error in xts(x, order.by = order.by, frequency = frequency, .CLASS = "integer", :
order.by requires an appropriate time-based object