Creating a data partition using caret and data.table

后端 未结 2 1479
既然无缘
既然无缘 2021-01-12 21:57

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(train         


        
2条回答
  •  被撕碎了的回忆
    2021-01-12 22:51

    The reason is that createDataPartition produces integer vector with two dimensions where the second could be losslessly dropped.
    You can simply reduce dimension of trainingRows using below:

    DT[trainingRows[,1]]
    

    The c() function from Bruce Pucci's answer will reduce dimension too.

    This minor difference vs. data.frame was spotted long time ago and recently I've made PR #1275 to fill that gap.

提交回复
热议问题