0

I am creating 10 folds using createFolds in the caret library, After creating the folds I want to access the data related to the Ids in each fold.

This line of code is working fine:

data[folds$Fold1,]

But when I access it by fold id, it gives an error:

data[folds[1],]

The error is: Error in [.default(xj, i) : invalid subscript type 'list'

Here is a complete sample code:

library(caret)
data=data.frame(V1=LETTERS)
folds <- createFolds(data[,1], k = 5, list = T, returnTrain = FALSE)
#this line is working fine
data[folds$Fold1,]
#this line gives error " invalid subscript type 'list' "
data[folds[1],]
Nobel
  • 1,485
  • 1
  • 16
  • 19

0 Answers0