Re: [R] Recursion in R ...

2007-07-07 Thread Uwe Ligges
Alberto Monteiro wrote: Ted Harding wrote: So I slickly wrote a recursive definition: Nnk-function(n,k){ if(n==1) {return(k)} else { R-0; for(r in (1:k)) R-(R+Nnk(n-1,k-r+1)) # ,depth)) } return(R) } You are aware that this is equivalent to: Nnk1 - function(n, k) {

Re: [R] Recursion in R ...

2007-07-07 Thread Ted Harding
On 07-Jul-07 10:34:03, Uwe Ligges wrote: Alberto Monteiro wrote: Ted Harding wrote: So I slickly wrote a recursive definition: Nnk-function(n,k){ if(n==1) {return(k)} else { R-0; for(r in (1:k)) R-(R+Nnk(n-1,k-r+1)) # ,depth)) } return(R) } You are aware that this is

Re: [R] Recursion in R ...

2007-07-07 Thread Duncan Murdoch
On 07/07/2007 7:15 AM, (Ted Harding) wrote: On 07-Jul-07 10:34:03, Uwe Ligges wrote: Alberto Monteiro wrote: Ted Harding wrote: So I slickly wrote a recursive definition: Nnk-function(n,k){ if(n==1) {return(k)} else { R-0; for(r in (1:k)) R-(R+Nnk(n-1,k-r+1)) # ,depth)) }

[R] Recursion in R ...

2007-07-06 Thread Ted Harding
Hi Folks, R has known speed issues for recursive definitions. There was a thread Extremely slow recursion in R? in August 2006 (24 Aug, from Jason Liao), with some interesting comparisons between programming languages. I'm re-opening the topic, with an ulterior motive (stated at the end

Re: [R] Recursion in R ...

2007-07-06 Thread Alberto Monteiro
Ted Harding wrote: So I slickly wrote a recursive definition: Nnk-function(n,k){ if(n==1) {return(k)} else { R-0; for(r in (1:k)) R-(R+Nnk(n-1,k-r+1)) # ,depth)) } return(R) } You are aware that this is equivalent to: Nnk1 - function(n, k) { prod(1:(n+k-1)) / prod(1:n)