Re: [R] how to store recursive results

From: X.H Chen <xchen_stat_at_hotmail.com>
Date: Fri 22 Sep 2006 - 15:14:41 GMT


Hi Patrick,

Thanks for your suggestion. I find your method works for the functions with integer paramters. For example,

If we have function f:
f<-function(i)
{

	if(i>1)
		i*f(i-1)
	else
		1

}

and then using:

ans <- vector("list", n)
for(i in 1:5) {
ans[[i]] <- f(i)
}

the ans should be:
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 6

[[4]]
[1] 24

[[5]]
[1] 120

But actually, we there is no such a "i" can be referrenced in f(), no parametric function for example, this will be a problem. Anyway, thanks a lot for your suggestions.

Cheers,

Xiaohui Chen

Dept. of Statistics
UBC, Canada

>From: Patrick Burns <pburns@pburns.seanet.com>
>To: "X.H Chen" <xchen_stat@hotmail.com>
>Subject: Re: [R] how to store recursive results
>Date: Fri, 22 Sep 2006 10:26:35 +0100
>
>It isn't clear to me exactly what you are asking, but
>I think that a list might be what you are after. Something
>like:
>
>ans <- vector("list", n)
>for(i in 1:n) {
>ans[[i]] <- ....
>}
>
>X.H Chen wrote:
>
>>Hi all,
>>
>>How to store recursive resutls from a function for each step without using
>>global operators <<-? Thanks ahead.
>>
>>Xiaohui Chen
>>
>>Dept. of Statistics
>>UBC, Canada
>>
>>_________________________________________________________________
>>Donít waste time standing in lineótry shopping online. Visit Sympatico /
>>MSN
>>
>>------------------------------------------------------------------------
>>
>>______________________________________________
>>R-help@stat.math.ethz.ch 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.
>>
>>



R-help@stat.math.ethz.ch 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. Received on Sat Sep 23 01:18:38 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 22 Sep 2006 - 15:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.