[R] how do I transform this to a for loop

Karl Brand k.brand at erasmusmc.nl
Mon Sep 6 10:46:06 CEST 2010


Hi Bill,

I didn't make the original post, but its pretty similar to some thing i 
would have queried the list about. But, as an R dilatante i find more 
curious your question-

"...but why would you want to do so?"

Is this because you'd typically use the given nine lines of explicit 
code to carve up a single dataset into nine symmetrical variants ? Or 
that some contextual information may affect how you would write the 
for() loop?

As i lack the experience to know any better, i perceive your for() loop 
as de rigour in efficient use of R, and the preferance of all 
experienced R user's. But not having any formal education in R or role 
models as such, its only an assumption (compeletely ignoring for the 
moment processing efficiency/speed, rounding error and such).

But which i now question! Explicit, simple crude looking code; or, 
something which demands a little more proficiency with the language?

cheers,

Karl



On 9/6/2010 6:16 AM, Bill.Venables at csiro.au wrote:
>
> sseq<- c(1, seq(5, 40, by = 5))
> for(i in 1:length(sseq))
> assign(paste("arima", i, sep=""), arima(data.ts[sseq[i]:(sseq[i]+200)], order=c(1,1,1)))
>
> ...but why would you want to do so?
>
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of lord12
> Sent: Monday, 6 September 2010 10:57 AM
> To: r-help at r-project.org
> Subject: [R] how do I transform this to a for loop
>
>
> arima1<- arima(data.ts[1:201], order = c(1,1,1))
> arima2<- arima(data.ts[5:205], order = c(1,1,1))
> arima3<- arima(data.ts[10:210], order = c(1,1,1))
> arima4<- arima(data.ts[15:215], order = c(1,1,1))
> arima5<- arima(data.ts[20:220], order = c(1,1,1))
> arima6<- arima(data.ts[25:225], order = c(1,1,1))
> arima7<- arima(data.ts[30:230], order = c(1,1,1))
> arima8<- arima(data.ts[35:235], order = c(1,1,1))
> arima9<- arima(data.ts[40:240], order = c(1,1,1))
>

-- 
Karl Brand <k.brand at erasmusmc.nl>
Department of Genetics
Erasmus MC
Dr Molewaterplein 50
3015 GE Rotterdam
P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268



More information about the R-help mailing list