"student.por" is a dataset that I trimmed down to 648 rows so I could do a four fold cross validation. Here is a link to the csv file if you would like to see it. student.por
"predictorDat1" is the same data set with just my predictor variables. I removed my chosen response variable "romantic" which is column 23.
student.por=student.por[-649,]
predictorDat1<-student.por[,-23]
g1=1:162
g2=163:324
g3=325:486
g4=487:648
Groups=data.frame(g1,g2,g3,g4)
Now when I run the code below I get this error:
"Error in model.frame.default(formula = student.por$romantic ~ ., data = predictorDat1[-Groups[, : variable lengths differ (found for 'school')"
predictions=c()
for(i in 1:4){
tree=rpart(student.por$romantic~., data=predictorDat1[-Groups[,i],],control=rpart.control(cp=.001))
predictions_per_fold=predict(tree,type="class",newdata=predictorDat1[Groups[,i],]) ##
predictions=c(predictions,as.character(predictions_per_fold))
}
Does anyone know why I'm having this issue? I would be so grateful for the help.