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 <[EMAIL PROTECTED]>
To: "X.H Chen" <[EMAIL PROTECTED]>
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
_________________________________________________________________
Dont waste time standing in linetry shopping online. Visit Sympatico /
MSN
------------------------------------------------------------------------
______________________________________________
[email protected] 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.
______________________________________________
[email protected] 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.