6

I am getting an error: argument "x" is missing, with no default Upon debugging, I found this out to be in the line : MyData1<- MyData()[,c(col(),col()+1)] I have tried to pass the argument as a single vector like MyData1<- MyData()[,p=c(col(),col()+1)]

Error: Error in [.data.frame: unused argument (p = c(col(), col() + 1))

This is just a snippet from my actual code:

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**
BENY
  • 317,841
  • 20
  • 164
  • 234
Jojo Acharya
  • 61
  • 1
  • 2
  • 4
  • What is `col()`? Is that a function you wrote? Is that a reactive object? It's not clear from your code chunk. Please make sure you provide a [reproducible example]https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example() with your question that include sample data that we can actually run and test. – MrFlick Jul 05 '17 at 20:14
  • Yes, Col() is a reactive object. Even upon trying to manually feed in numbers it is giving the same error. – Jojo Acharya Jul 05 '17 at 20:17
  • 1
    You've defined both `col()` and `Col()`? (R is case sensitive). – MrFlick Jul 05 '17 at 20:18
  • MyData() is the table one gets to upload, and Col() is the option given to input the column number, one wishes to explore. – Jojo Acharya Jul 05 '17 at 20:19
  • 2
    `col` is a function in base R. So when you use `col()`, that function is looking for an argument `x` and not finding it. I suggest using more descriptive variable names or storing all your reactive values in a `reactiveValues(...)` list. – Nathan Werth Jul 05 '17 at 20:20

1 Answers1

2

Looking at your code and tracing the sequence of steps to MyData1, I identified these lines:

  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)]

Assuming MyData is an object which already exists as a matrix or data.frame, the issue is because you are not giving the Extract operator an index specifying the rows or column you wish to extract. Instead you've passed the col function without specifying a matrix-like object for it to use.

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

Should Be

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

However, I must ask, what are you trying to accomplish with this subset operation? There maybe a more elegant and compact solution that is cleaner than using the col function to specify the columns you'd like to extract from MyData1.

Justin
  • 1,360
  • 12
  • 15