请问各位大神如何在某次循环报错后忽略这个错误,跳出这次循环继续下一次循环呢?
我的目的是计算不同区站号下,年份与日序的回归系数,因为有些回归结果是下面这种有缺失值的会报错,
Estimate Std. Error t value Pr(>|t|)
(Intercept) 178 NaN NaN NaN
查了些帖子加了能跳出循环的条件,
b <- unique(data0$区站号)
fit <- c()
for(i in 1:100){
x<- subset(xs,xs$区站号==b)
x=as.data.frame(lapply(x,as.numeric))
jg <- lm(x$日序~x$年)
fit <- try(coef(summary(jg))[2,c(1,2,4)])
if("try-error"%in% class(fit)){
next
} else
{
fit <- rbind(fit,c(b,coef(summary(jg))[2,c(1,2,4)]))
break
}
}
但还是总是报错是什么原因呢?“In rbind(fit, c(b, coef(summary(jg))[2, c(1, 2, 4)])) :
number of columns of result is not a multiple of vector length (arg 1)”
附件列表