当我工作被困在这里时,如果有人可以协助我解决问题,我将不胜感激,下面是代码和错误消息供您参考。
library(caTools)
split_data <- sample.split(filter_data_1$spend, SplitRatio = 0.75)
split_data
train_data <- subset(filter_data_1, split == TRUE)
test_data <- subset(filter_data_1, split == FALSE)
错误讯息:
test_data <- subset(filter_data_1, split = = FALSE)
错误:
“test_data&lt; - subset(filter_data_1,split ==”)中的意外'=' test_data&lt; - subset(filter_data_1,split == FALSE) 拆分错误== FALSE:
比较(1)仅适用于原子和列表类型
答案 0 :(得分:1)
此示例适用于我:
library(caTools)
library(MASS)
data(cats)
filter_data_1 <- cats
split_data <- sample.split(filter_data_1$Sex, SplitRatio = 0.75)
split_data
train_data <- subset(filter_data_1, split_data == TRUE)
test_data <- subset(filter_data_1, split_data == FALSE)
答案 1 :(得分:0)
split_data = sample.split(filter_data_1$spend, SplitRatio = 0.75) train_data = subset(filter_data_1, split_data == TRUE) test_data = subset(filter_data_1, split_data == FALSE)
因为在第一行数据集已经分裂了。