错误:参数" x"缺少,没有默认值

时间:2017-07-05 20:12:41

标签: r rstudio shiny shinydashboard

我收到一个错误:参数&#34; x&#34;缺少,没有默认值 经过调试,我发现这就行了: 的 MyData1<- MyData()[,c(col(),col()+1)] 我试图将参数作为单个向量传递 的 MyData1<- MyData()[,p=c(col(),col()+1)]

  

错误:[.data.frame:unused参数错误(p = c(col(),col()+   1))

这只是我实际代码的一小部分:

TotalTS<-ts(MyData()[,Col()],start=Start(),frequency = Fre())
    InsampleTs<-window(TotalTS,start = c(Start(),1),end=c(2017,5))
    TotalTS1<-ts(MyData()[,Col()+1],start=Start(),frequency = Fre())
    InsampleTs1<-window(TotalTS1,start = c(Start(),1),end=c(2017,5))

    MyData1<- MyData()[,c(col(),col()+1)]
    MyData1$util1<-MyData1[,1]*100/MyData1[,2]
    popj<-nrow(MyData())-length(InsampleTs)


    if(input$F6==1){
      if(input$AM==1){

        forecast32<-hw(InsampleTs,h=Col1(),level = input$CI2)
        forecast32_1<-hw(InsampleTs,h=Col1(),level = input$CI2)

        c<-as.matrix(forecast32$x)
        d<-as.matrix(forecast32_1$x)

        c1<-as.matrix(forecast32$fitted)
        d1<-as.matrix(forecast32_1$fitted)
        util2<-(c1*100)/d1
        util1<-(c*100)/d
        c11 <- as.matrix(forecast32$mean[1:popj])
        d11<- as.matrix(forecast32_1$mean[1:popj])
        c12 <- as.matrix(forecast32$lower[1:popj])
        d12<- as.matrix(forecast32_1$lower[1:popj])
        c13 <- as.matrix(forecast32$upper[1:popj])
        d13<- as.matrix(forecast32_1$upper[1:popj])

        c111 <- c11*100/d11
      c112<- c12*100/d12
        c113 <- c13*100/d13
        MyData1$util2 <- util2
        MyData1 <- MyData1[,c(col(),col()+1)]

        e<-as.matrix(forecast32$mean[-c(1:popj)])
        f<-as.matrix(forecast32_1$mean[-c(1:popj)])
        e2<-as.matrix(forecast32$upper[-c(1:popj)])
        f2<-as.matrix(forecast32_1$upper[-c(1:popj)])
        e1<-as.matrix(forecast32$lower[-c(1:popj)])
        f1<-as.matrix(forecast32_1$lower[-c(1:popj)])

        e111 <- e*100/f
        e113<- e2*100/f2
        e112 <- e1*100/f1

       r<- cbind(e111,e112,e113)
       colnames(r) <- c("Predicted","lower Limit","Upper Limit")

        MyData1 <- ts(MyData1,start=c(Start(),1), end=c(2017,5), frequency=Fre())
        #r<-ts(r,start=c(2017,6),end=c((Hstar()+2),Fre()))
        r<-ts(r,start=c(2017,6),end=c(2019,6), frequency = 12)
        autoplot(ts( cbind(r,MyData1),start = c(Start(),1),frequency=Fre() ),facets = F)
        }**strong text**

1 个答案:

答案 0 :(得分:1)

查看您的代码并跟踪MyData1的步骤序列,我确定了以下几行:

  1 c1<-as.matrix(forecast32$fitted)
  2 d1<-as.matrix(forecast32_1$fitted)
  3 util2<-(c1*100)/d1
  4 MyData1$util2 <- util2
  5 MyData1 <- MyData1[,c(col(),col()+1)]

假设MyData是一个已作为矩阵或data.frame存在的对象,问题是因为您没有给Extract运算符指定要提取的行或列的索引。相反,您已经通过col函数而未指定类似矩阵的对象供其使用。

 5 MyData1 <- MyData1[,c(col(),col()+1)]

应该

5 MyData1 <- MyData1[,c(col(x),col(x)+1)]

但是,我必须问,你想用这个子集操作完成什么?可能有一个更优雅和紧凑的解决方案,比使用col函数指定您想要从MyData1中提取的列更清晰。