Hello,

Try the following.


#cnames <- names(tryout)  # in your code, use this one
cnames <- c("Volume", "Price1", "Price2", "Price3", "Price4", "Price5", 
"Trend", "Seasonaliy")

price <- cnames[grep("Price", cnames)]
resp <- cnames[1]
regr <- cnames[7:8]

#lm.list <- vector("list", 5)
for(i in 1:5){
     regress <- paste(price[i], paste(regr, collapse = "+"), sep = "+")
     fmla <- paste(resp, regress, sep = "~")
     print(fmla)
     #lm.list[[i]] <- lm(as.formula(fmla), data = tryout)
}

Hope this helps,

Rui Barradas
Em 26-09-2012 08:08, Krunal Nanavati escreveu:
> Hi,
>
>
>
> I am trying to run many different regressions using a FOR Loop.
>
>
>
> The input data that is read into R has the following variables
>
>
>
> ·         Volume
>
> ·         Price1
>
> ·         Price2
>
> ·         Price3
>
> ·         Price4
>
> ·         Price5
>
> ·         Trend
>
> ·         Seasonality
>
>
>
> I want to run 5 regressions, with the Volume as an dependent variable and
> Price, Trend & Seasonality as independent variables. I have read the above
> mentioned variables in a variable called "tryout"
>
>
>
> I am entering the following syntax in R
>
>
>
>> for(i in 1:5)
> + {
>
> + result[i]=lm(Volume~Price[i]+Trend+Seasonaliy,data=tryout)
>
> + summary(result[i])
>
> + }
>
>
>
> After running these lines...I am getting the following error message
>
>
>
> Error in eval(expr, envir, enclos) : object 'Price' not found
>
>
>
> Can someone help me out with this error message. Appreciate for your time
> and consideration.
>
>
>
>
>
>
>
> Thanks & Regards,
>
>
>
> Krunal Nanavati
>
> Solutions Manager - Cogitaas
>
> 9769-919198
>
> 	[[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> 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.


	[[alternative HTML version deleted]]


