I have a problem with doing cross validation I did 10-fold cross validation and I got following error
Error in data[currentFold, ] : object of type 'closure' is not subsettable
Here are codes which I used:
k <- 10;
folds <- cvsegments(nrow(data2), k);
result1 <- rep (NA, nrow (data2))
insituValidation <- rep (NA, nrow (data2))
for (fold in 1 : k) {
currentFold <- folds[[fold]]
trainDat <- data2[-currentFold,]
model3 = nls(Height ~ a*(Diameter)^2+b*Diameter+c, data = data2, start = list(a = 1.2, b=.9,c=.5), algorithm="port")
#end model
# The results of the predictions of the model
result1 [currentFold] <- predict(model3, data[currentFold,])
insituValidation <- data2[currentFold,3]
}
I used the same codes in another dataset before and It worked But now with new dataset, the mentioned problem occurs.
Please help me to find solution.