data(kyphosis)
ky<- kyphosis
这样我就制作了一个包含原始数据 40% 的数据集。
ky_40 <- ky[sample(1:nrow(ky), nrow(ky)*0.4,replace=FALSE),]
通过这个声明,我想制作一个数据集,其中包含原始数据的 60%,不包括
ky_40.
ky_the_others<- ???????
如何制作最后的代码?
最佳答案
只需将样本从提取中移出,以便您可以再次引用它:
ky <- mtcars
## Here, I've moved the sampling out of your extraction
forty <- sample(1:nrow(ky), nrow(ky)*0.4,replace=FALSE)
## Now you can extract whatever you want
ky[ forty, ] # This will be the 40% of original dataset
ky[-forty, ] # This will be the remaining rows.
关于r - 采样后分割数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20826858/