Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.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_Function_Dplyr_Environment - Fatal编程技术网

R 未识别功能输入-本地和;全球环境问题

R 未识别功能输入-本地和;全球环境问题,r,function,dplyr,environment,R,Function,Dplyr,Environment,我正在编写一个函数,将我定期对时间序列数据采取的操作组合在一起。我在脚本中包含了我正在使用的所有库,因为我认为我的问题可能与plyr/dplyr(正确地)超级具体地描述每个变量的环境有关 第一个函数工作得很好,但当进入第二个函数时,R无法识别输入为“x”,而是抛出错误:“error in eval(predvars,data,env):找不到对象“x” 为什么会这样 library(plyr) library(dplyr) library(caret) library(xts) library(

我正在编写一个函数,将我定期对时间序列数据采取的操作组合在一起。我在脚本中包含了我正在使用的所有库,因为我认为我的问题可能与plyr/dplyr(正确地)超级具体地描述每个变量的环境有关

第一个函数工作得很好,但当进入第二个函数时,R无法识别输入为“x”,而是抛出错误:“error in eval(predvars,data,env):找不到对象“x”

为什么会这样

library(plyr)
library(dplyr)
library(caret)
library(xts)
library(forecast)
library(imputeTS)
library(lubridate)

x1 = arima.sim(list(order = c(0,1,0)), n = 119)

timetrend <- function(x, starts, ends, frequency) { 
  y <- list()
  y[[1]] <- ts(x, start = starts, end = ends, frequency = frequency)
  y[[2]] <- decompose(y[[1]])
  y[[3]] <- y[[1]] - y[[2]]$seasonal - y[[2]]$random
  return(y)
}

plottime <- function(x) { #takes a timetrend list as input
  t <- tslm(x[[3]] ~ trend)
  plot(x[[3]])
  lines(t$fitted.values)
  return(t)
}
库(plyr)
图书馆(dplyr)
图书馆(插入符号)
图书馆(xts)
图书馆(预测)
图书馆(imputeTS)
图书馆(lubridate)
x1=arima.sim(列表(顺序=c(0,1,0)),n=119)

timetrend我可以使用以下代码使其工作

plottime <- function(x) { #takes a timetrend list as input
  y=x[[3]]
  t <- tslm(formula = y ~ trend)
  plot(x[[3]])
  lines(t$fitted.values)
  return(t)
}

plottime我可以使用以下代码使其工作

plottime <- function(x) { #takes a timetrend list as input
  y=x[[3]]
  t <- tslm(formula = y ~ trend)
  plot(x[[3]])
  lines(t$fitted.values)
  return(t)
}

plottime感谢您的关注-这段代码对我来说运行良好,结果已创建。我的系统报告说,
decompose
来自igraph软件包。因此,我现在得到的结果和结果与您使用
stats::decompose
时得到的结果和结果相同。当您为
result
-对象编制索引时,它删除了
result
的第二个元素,即存储
$trend
项的位置。查看
str(result)
tslm
的代码,感谢您的查看-这段代码对我来说运行良好,结果已创建。我的系统报告说,
decompose
来自igraph包。因此,我现在得到的结果和结果与您使用
stats::decompose
时得到的结果和结果相同。当您为
result
-对象编制索引时,它删除了
result
的第二个元素,即存储
$trend
项的位置。看看
str(result)
tslm的代码
谢谢-是的,当我取出索引时,它工作得很好。如果知道是什么导致了错误,那就太好了。谢谢。谢谢-是的,当我拿出索引时,它工作得很好。如果知道是什么导致了错误,那就太好了。谢谢