[R] How to iterate through different arguments?

Gabor Grothendieck ggrothendieck at gmail.com
Thu Oct 7 02:57:49 CEST 2010


On Wed, Oct 6, 2010 at 10:16 AM, lord12 <trexinsd at yahoo.com> wrote:
>
> Thanks a lot! I have one other question,however. If I want to have two
> garchFits,  garchFit(~aparch(1,1), data = sunspot.year) and
> garchFit(~arma(2,1)+apaarch(1,1), data = sunspot.year), how do I automate
> the creation of these models?
>
> for(k in 1:2)
> {
>  garchFit~...,data = sunspot.year),
> }
>
> I am not sure what to put in the ...



Set up a character vector of terms, Terms, such as

  Terms <- c("x1", "x2", "x3", "x4")

and then replace the fo<- line in my second solution with:

  fo <- as.formula(paste("y1", paste(Terms[1:k], collapse = "+"), sep = "~"))


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list