[R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread casperyc
=== myf=function(ds=1){ x=rnorm(10) y=rnorm(10) { #start of if if (ds==1) { list(x,y) } else (ds==2) { plot(x,y) } } # end of if } # end of function === Hi All, the problem i am having here is, that I want to be able to control the display, lf

Re: [R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread Peter Alspach
-help@r-project.org Subject: [R] writing function ( 'plot' and 'if') problem === myf=function(ds=1){ x=rnorm(10) y=rnorm(10) { #start of if if (ds==1) { list(x,y) } else (ds==2) { plot(x,y) } } # end of if } # end of function

Re: [R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread casperyc
what i am triyng to do is when ds=1 give me a list ds=2 plot Thanks casper -- View this message in context: http://n4.nabble.com/writing-function-plot-and-if-problem-tp1839091p1839125.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread David Winsemius
On Apr 13, 2010, at 5:41 PM, casperyc wrote: === myf=function(ds=1){ x=rnorm(10) y=rnorm(10) { #start of if if (ds==1) { list(x,y) } else (ds==2) ?if That seems odd. I would expect this function to return TRUE or FAKSE rather than proceeding to a plot function.

Re: [R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread David Winsemius
On Apr 13, 2010, at 5:41 PM, casperyc wrote: === myf=function(ds=1){ x=rnorm(10) y=rnorm(10) { #start of if if (ds==1) { list(x,y) } else (ds==2) { plot(x,y) } } # end of if } # end of function === Hi All, the problem i am having here is,

Re: [R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread RICHARD M. HEIBERGER
The spurious condition (ds==2) is actually interpreted as the action taken by the else statement. Then the braced plot statement is seen as the next statement after the conclusion of the if () {} else () statement. [[alternative HTML version deleted]]

Re: [R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread David Winsemius
On Apr 13, 2010, at 10:58 PM, RICHARD M. HEIBERGER wrote: The spurious condition (ds==2) is actually interpreted as the action taken by the else statement. Then the braced plot statement is seen as the next statement after the conclusion of the if () {} else () statement. I did