Re: [R] default values

2008-03-13 Thread Prof Brian Ripley
On Thu, 13 Mar 2008, Dwayne Blind wrote: > Thanks a lot. > > You were right :-) > > Professor Ripley can I use your SPLUS book for R too ? 'Modern Applied Statistics with S' and 'S Programming' both cover S and its implementations in S-PLUS and R. However, 'Modern Applied Statistics with S-PLUS

Re: [R] default values

2008-03-13 Thread Dwayne Blind
Thanks a lot. You were right :-) Professor Ripley can I use your SPLUS book for R too ? 2008/3/12, Prof Brian Ripley <[EMAIL PROTECTED]>: > > On Wed, 12 Mar 2008, Dwayne Blind wrote: > > > > Dear R users, > > > > I wrote the following toy example to explain my problem : > > > > a=0 > > f=functio

Re: [R] default values

2008-03-12 Thread Prof Brian Ripley
On Wed, 12 Mar 2008, Dwayne Blind wrote: > Dear R users, > > I wrote the following toy example to explain my problem : > > a=0 > f=function(x,y,z) { >if (a==0) x[1]+x[2]+y >if (a!=0) x[1]+x[2]+y+z > } > f(1:2,3) > > > I have not specified z and I get an error. What was the error? It work

Re: [R] default values

2008-03-12 Thread Ravi Varadhan
You just need to return the values computed when a==0 and when a!=0. a=0 f=function(x,y,z=0) { if (a==0) return(x[1]+x[2]+y) if (a!=0) return(x[1]+x[2]+y+z) } > f(1:2,3) [1] 6 > Ravi. --- Ravi Varadhan, Ph