Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 润滑油是否每天使用_R_Xts - Fatal编程技术网

R 润滑油是否每天使用

R 润滑油是否每天使用,r,xts,R,Xts,我试图从这个例子中了解lubridate是否可以应用于apply.daily,但不太明白如何做到这一点。 我是否可以通过apply.daily获得使用lubridate的任何参考,以便我可以使用apply.daily排除周末 编辑:以里奇·科顿的例子为指导,我写了以下内容: > is.weekend <- function(x) { + w <- as.POSIXlt(x) + w %in% c(1,7) + } > apply.daily(core

我试图从这个例子中了解lubridate是否可以应用于apply.daily,但不太明白如何做到这一点。 我是否可以通过apply.daily获得使用lubridate的任何参考,以便我可以使用apply.daily排除周末

编辑:以里奇·科顿的例子为指导,我写了以下内容:

> is.weekend <- function(x) {

+    w <- as.POSIXlt(x)

+    w %in% c(1,7)

+ }

> apply.daily(core[!is.weekend(x)],dfun)

Error in as.POSIXlt.default(x) :

  do not know how to convert 'x' to class "POSIXlt"

> apply.daily(core[!is.weekend(index(x))],dfun)

Error in as.POSIXlt.numeric(x) : 'origin' must be supplied

> alpha <- core[!is.weekend(index(x))]

Error in as.POSIXlt.numeric(x) : 'origin' must be supplied

> 
>is.weekend apply.daily(核心[!is.weekend(索引(x))],dfun)
as.POSIXlt.numeric(x)中出错:必须提供“origin”
>阿尔法

我的错误在哪里?我是否缺少特定的库?

创建您的时间序列

x <- today() + hours(0:(24 * 14))
time_series <- xts(rnorm(length(x)), x)

您要传递给
的变量
x
是什么。weekend
?不管它是什么,它都不能转换为
POSIXlt
。此外,检查类
POSIXlt
的对象是否等于1或7也不起作用。您需要检查%c(0,6)中的
w$wday%
或使用我建议的
lubridate::wday
功能。
is.weekend <- function(x)
{
  day_of_week <- wday(x, label = TRUE)
  day_of_week %in% c("Sat", "Sun")
}
apply.daily(time_series[!is.weekend(x)], max)