如何解决:"as.POSIXct.numeric(X [[2L]],...)中的错误:必须提供'origin'" [英] How to solve: "Error in as.POSIXct.numeric(X[[2L]], ...) : 'origin' must be supplied"
问题描述
我们创建了以下循环以绘制数据的不同部分(使用包"latticeExtra").
we have created the following loop to plot the different parts of the data (with the package "latticeExtra").
library("latticeExtra")
All_dates<-unique(fad$Meet_date)
for (i in 1:11) { Date.i <- All_dates[i]
layoutno <- unique(fad[fad$Meet_date == Date.i,28] )
Data.i <- fad[fad$Meet_date == Date.i, ]
Data.i$newtime <- as.POSIXct(Data.i$DateTime)
prop <- with(Data.i,tapply(newtime,klasse, max))-with(Data.i,tapply(newtime,klasse, min))
png(paste(Date.i, ".png", sep = ""), height = 20, width = 30, units = "cm", res = 400)
dog <- xyplot(Ratio ~ Meet_times |as.factor(klasse), data = Data.i, main = paste(Date.i),
layout = c(layoutno,1), scales = list(x = list(relation = "free",format = "%H:%M")),
xlab = "Time of measurement", ylab = "Ratio CH4/CO2")
print(resizePanels(dog,w = prop))
dev.off() }
但是,我们得到了:as.POSIXct.numeric(X [[2L]],...)中的错误:必须提供'origin'. 我是R的大手,所以我不知道这个问题可能在哪里..我的同事似乎也迷路了..我知道这是一个大代码,但我还是希望有人能看到这个问题.在该网站和Google上进行了几次搜索,但这并没有给我带来任何帮助.
However, we get this: Error in as.POSIXct.numeric(X[[2L]], ...) : 'origin' must be supplied..
I am a big noob with R, so I have no idea where this problem could lie.. My collegue also seems to be lost.. I know it is a big code, but I kinda hoped someone sees the problem rigthaway.. I tried several searches on this website and on Google, but this did not get me anything useful.
请帮忙?提前非常感谢!
Please, help? Thanks a lot in advance!
推荐答案
好,这个问题很容易解决,但是您需要小心以确保正确的日期转换.问题在于,您正在将数字传递给as.POSIXct
而不是Date
对象,并且当您传递整数时,您需要提供一个原始日期,以便它可以计算偏移量.例如:
Well, it's easy to get this problem to go away, but you need to be careful to get the date conversions right. The problem is that you are passing a number to as.POSIXct
and not a Date
object, and when you pass an integer, you need to give an origin date, so that it can compute the offset. For example:
> date<-as.Date("2013-10-18")
> as.POSIXct(date)
[1] "2013-10-17 20:00:00 EDT"
> date0<-unclass(date)
> date0
[1] 15996
> as.POSIXct(date0)
Error in as.POSIXct.numeric(date0) : 'origin' must be supplied
真正的问题是,如何在fad$Meet_date
中表示日期(以及为什么要将其转换为POSIXct).正确的来源和转换取决于fad$Meet_date
代表什么.
The real question is, how are you representing your dates in fad$Meet_date
(and also why do you want to convert them to POSIXct). The correct origin and conversion will depend on what fad$Meet_date
represents.
这篇关于如何解决:"as.POSIXct.numeric(X [[2L]],...)中的错误:必须提供'origin'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!