Input in a lm (linear regression) function in R -
i doing lm in r using vectors
y<-c(1,0,1,2,5,1,4,6,2,3,5,4,6,8,4,5,7,9,7,6) x<-c(60,63,65,70,70,70,80,80,80,80,85,89,90,90,90,90,94,100,100,100) rg<-lm(y ~ x) summary(rg) x1<-c(61,64,69,73,76,77,82,84,87,90,95,99,100,101,102,103,104,107,110,120)
when use x1 input predict
y1 <- predict(rg,x1 )
i have error:
"error in eval(predvars, data, env) : numeric 'envir' arg not of length one"
this error doesn't occur if use data.frame object input...i dob't understand why need data.frame , vector doesn't work
am doing wrong??
thanks in advance
i agree gregor. x1, "newdata" should data.frame.
y1 <- predict(rg, as.data.frame(x1))
Comments
Post a Comment