Appending Data Frame in Loop: cannot coerce type 'closure' to vector of type 'list'

Viewed 14

I am trying to perform 10-fold cross-validation within a loop. I would like to put the predictive valeus of the test set into an empty dataframe for each of the 10 folds. The code I have so far is:


for(i in 1:10){
    testIndexes <- which(folds==i,arr.ind=TRUE)
    testData <- Data[testIndexes, ]
    trainData <- Data[-testIndexes, ]
    fit_train<-lmer(values~PTAH_base+PTAL_base+PTAU_base+ChemoDose+RT+(1|SAMPLE_NAME),data=trainData)
    pred_test <- predict(fit_train,newdata=testData,allow.new.levels=TRUE)
    df = rbind(df,pred_test)
}

Where the last line 'df = rbind(df,pred_test)' is giving me the error:

Error in base::rbind(...) : 
  cannot coerce type 'closure' to vector of type 'list'

What am I doing wrong? Is there a better way to append a dataframe in a loop?

0 Answers
Related