代码在R中运行得很好,但是当我在R Markdown中运行时,得到一个“参数长度为零”的错误。只需运行一个循环,以50%的比例将概率输出拆分为0或1。
查看了一些类似的帖子,但在移动到markdown时没有找到任何关于问题的东西。
for (i in 0: (nrow(test)-1)){
i <- i+1
if (test$pred_basemodel[i] < 0.5){
test$pred_basemodel[i] <- 0
}
else {
test$pred_basemodel[i] <- 1
}
}谢谢你的建议!
发布于 2020-02-23 05:40:53
我认为您可以在for循环中删除i <- i+1,因为i是将自动通过1:nrow(test)运行的迭代器。此外,您可以使用1:nrow(test)而不是0:(nrow(test)-1)作为for循环条件,因为您的索引自然从1开始。
你可以试试下面的代码
for (i in 1:nrow(test)){
if (test$pred_basemodel[i] < 0.5){
test$pred_basemodel[i] <- 0
}
else {
test$pred_basemodel[i] <- 1
}
}https://stackoverflow.com/questions/60357054
复制相似问题