I have a data.table in R which I want to use with caret package
set.seed(42)
trainingRows<-createDataPartition(DT$variable, p=0.75, list=FALSE)
head(trainingRows) # view the samples of row numbers
However, I am not able to select the rows with data.table. Instead I had to convert to a data.frame
DT_df <-as.data.frame(DT)
DT_train<-DT_df[trainingRows,]
dim(DT_train)
the data.table alternative
DT_train <- DT[.(trainingRows),] requires the keys to be set.
Any better option other than converting to data.frame?