Try this:

lapply(names(boston), function(x)summary(update(lm(MEDV ~ 1, boston), ~
get(x))))

On Mon, Sep 20, 2010 at 2:03 PM, Soyeon Kim <yunni0731@gmail.com> wrote:

> Dear All,
>
> I have data which contains 14 variables. And I have to regress one of
> variables on each variable (simple 13 linear regressions)
>
> I try to make a loop and store only R-squared
>
>  colnames(boston)
>  [1] "CRIM"    "ZN"      "INDUS"   "CHAS"    "NOX"     "RM"      "AGE"
>  [8] "DIS"     "RAD"     "TAX"     "PTRATIO" "B"       "LSTAT"   "MEDV"
>
> name <-  colnames(boston)
>
> r <- rep(0, 13)
> for(i in 1: 13) {
>  r[i] <- summary(lm(MEDV ~ name[i], data = boston))$r.squared
> }
>
> but this doesn't work because name have " " for each variable. How to
> remove " " for name of each variable?
> Or do you know the way I can do regression MEDV on each variable?
>
> Thank you ahead,
> Soyeon
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]

