[R] Plot in function

R. Michael Weylandt michael.weylandt at gmail.com
Tue Nov 6 19:45:07 CET 2012


On Tue, Nov 6, 2012 at 4:44 PM, Pauli <paul.kraus85 at web.de> wrote:
> Hello,
>
> I am a R beginner and I have a question about a litte function I found.
> Here is the code:
>
> # Gambler's Ruin Problem.
> # seed capital:                k
> # rounds:                      n
> # probability of success:                  p
> # number of trials:             N
> # graphical output (yes/no): draw
> # Wait for new graphic (yes/no):   ask
>
> ruin<- function( N = 1, n = 10, k = 1, p = 1 / 2,
>                  draw = FALSE, ask = FALSE ){
>    if(draw)
>      par( ask = ask )
>    r <- 0
>    for( i in 1:N ){
>      x <- k + cumsum (sample( c(-1, 1),replace = TRUE, n,prob = c(1-p, p)))
>      if( min(x) <= 0 ){
>        r <- r + 1
>        if(draw)
>          ruin.plot( k, x, col = "red",main = paste(i, "th trial: ruin!" ) )
>      }
>      else if(draw)
>             ruin.plot( k, x, main = paste( i, "th trial: no ruin" ),ylim =
> c( 0, max(x) ) )
>    }
>    return(r / N)
> }
>
> Now I want to start it with for example
> "ruin(N=100,n=1000,k=50,draw=TRUE,ask=TRUE)" but i received the message,
> that there is an unused argument: (col = "red",main = paste(i, "th trial:
> ruin!" ) ).
> What is wrong with the code?
>

It looks like there's a problem in the call to ruin.plot() but since
we don't have the source for that, we can't really help you out.

Can you cite the code you're using / provide it in full if it's
original to you? A fully reproducible example would be awesome:

http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

Cheers,
Michael




More information about the R-help mailing list