我使用data.frame trind来训练机器学习回归,从而做出预测( pred )。pred比trind大100倍,但两者之间存在重叠。
我想将预测评级替换为来自trind的培训评级,以生成test,我将看到它在基准测试中的表现。我目前在subset的帮助下完成了这个任务,但是它是一个庞大的代码。有没有人有更简洁的方法?
trind <- data.frame(c(1,3,5), c(4,3,4))
names(trind) <- c("ID", "Rating")
pred <- data.frame(1:5, c(1,2,3,4,5))
names(pred) <- c("ID", "Rating")
temp <- subset(pred, pred$ID %in% trind$ID)
temp$Rating <- trind$Rating
temp2 <- subset(pred,! pred$ID %in% trind$ID)
test <- rbind(temp, temp2)发布于 2013-12-01 21:55:14
这是一个通用的解决方案。首先,通过将trind和pred结合起来创建一个数据框架。
test <- rbind(trind, pred)其次,删除与复制的IDs相关联的行。
test <- test[!duplicated(test$ID), ]发布于 2014-02-08 04:40:04
这就是你要找的吗?假设您已经拥有了pred和trind:
pred[ pred$ID %in% trind$ID, "Rating" ] <- trind$Ratinghttps://stackoverflow.com/questions/20317737
复制相似问题