请教大家,遇到一个问题,怎么在loop里面用lm function求coefficient?我写的code如下:
"m=500
b2=numeric(m)
for (i in 1: m){
x=runif(100,0,10)
error1=rnorm(100,0,2)
y1=2+3*x+error1
b2=lm(y1 ~ x)$coefficient
}
hist(b2)
“
r 一直warning:In b2 = lm(y1 ~ x)$coefficient :
number of items to replace is not a multiple of replacement length
麻烦大家帮忙看看应该怎么改,谢谢