I am trying to normalize the data frame before prediction but I get this error :
Error in seq_len(nrows)[i] :
only 0's may be mixed with negative subscripts
Called from: top level
Here is my code :
 library('caret')
 load(file = "some dataset path here") 
 DummyDataSet =  data
 attach(DummyDataSet)
 foldCount = 10
 classifyLabels = DummyDataSet$ClassLabel
 folds = createFolds(classifyLabels,k=foldCount)
 for (foldIndex in 1:foldCount){
    cat("----- Start Fold -----\n")
    #holding out samples of one fold in each iterration
    testFold    = DummyDataSet[folds[[foldIndex]],]     
    testLabels  = classifyLabels[folds[[foldIndex]]]
    trainFolds  = DummyDataSet[-folds[[foldIndex]],]
    trainLabels = classifyLabels[-folds[[foldIndex]]]
#Zero mean unit variance normalization to ONLY numerical data
for (k in 1:ncol(trainFolds)){
   if (!is.integer(trainFolds[,k])){
      params = meanStdCalculator(trainFolds[,k])
      trainFolds[,k] = sapply(trainFolds[,k], function(x) (x - params[1])/params[2])
      testFold[,k]  = sapply(testFold[,k],  function(x) (x - params[1])/params[2])
   }
}
  meanStdCalculator = function(data){  
    Avg  = mean(data)
    stdDeviation  = sqrt(var(data))
    return(c(Avg,stdDeviation))
  }
  cat("----- Start Fold -----\n")
}
where trainFolds is a fold creating by caret package and its type is data.frame.
I have already read these links : 
but I couldn't find out what is wrong with the indexes? anybody can help me?
 
    