'Cross Validation without caret in R

Since the model (package fastNaiveBayes) that I am using is not in the built-in library of the caret package, I am trying to make a k-fold cross validation in R without using the caret package. Does anyone have a solution to this?

Edit: Here is my code so far from what I learned on how to do cv without caret. I am very certain something is wrong here.

library(fastNaiveBayes)


k<- 10
outs <- NULL
proportion <- 0.8
for (i in 1:10)
{
  split <- sample(1:nrow(data), round(proportion*nrow(data)))
  traindata <- data[split,]
  testdata <- data[-split,]

y <- traindata$Label

x <- traindata[,0 - 15:ncol(traindata)]

model <- fnb.train(x, y=y, priors = NULL, laplace=0, 
               distribution = fnb.detect_distribution(x, nrows = nrow(x)))
model




test1 <- testdata[,0 - 15:ncol(testdata)]
pred <- predict(model, newdata = test1)


cm<- table(testdata$Label, pred)


print(confusionMatrix(cm))

}

It gave me 10 different results and I think that's not how it cross validation is supposed to work. I'm an entry-level R learner and I appreciate so much to receive enlightenment from this



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source