[R] Plot in function

Pauli paul.kraus85 at web.de
Tue Nov 6 17:44:06 CET 2012


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?

Best regards
Pauli



--
View this message in context: http://r.789695.n4.nabble.com/Plot-in-function-tp4648576.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list