开发者

Error Messages in R after a for loop

开发者 https://www.devze.com 2022-12-18 07:10 出处:网络
This is a bit of a shot in the dark, but I have a script that does exactly what I expect it to do, yet, at the very end of the script I get an error like this:

This is a bit of a shot in the dark, but I have a script that does exactly what I expect it to do, yet, at the very end of the script I get an error like this:

Error in `[<-.data.frame`(`*tmp*`, "label", val开发者_运维问答ue = c(1L, 0L)) : 
  replacement has 2 rows, data has 0

In terms of an answer, I'm looking for general suggestions on how to track errors like this in R, best practices for using loops and double checking that they "made it through".

Any thoughts, suggestions, or past experiences that could relegate or inform an error message like this?


I already included my comments about debugging practices in this related question. But regarding the specific message that you show here: that means that you're trying to write out 2 rows to some dataset that has 0 rows. Something like this:

x <- data.frame(y=NULL)
x$y <- 1:2
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号