[R-SIG-Finance] beginner asks:

jk alte at comcast.net
Tue Oct 31 06:01:46 CET 2006


below is from an available online textbook.  as an experienced user can 
see, the below text is "how" to determine %s of winning come-out rolls 
(7 or 11) in a 1000 games of craps.  I cannot figure out how to stick 
this query into R correctly.  at the first prompt i make the vector of 
length 1000 filled with 0s called "wins"
i hit enter.
get a fresh prompt, so far so good. But the rest of the example in the 
book does not seem to paste so simply.
What is frustrating is the first example in this book shows the prompt 
at each line. So it's clear what to type and where. But in this one, 
only the second example, i've tried a dozen variations always with the 
correct text sequentially to no avail.  syntax errors.  I'd sure be 
grateful for some guidance.  thanks, john kuhn


Now we have to figure out how to simulate the Come-out roll and decide 
whether
the shooter wins. Clearly, we begin by simulating the roll of two dice. 
So our snippet
expands to
# make a vector of length 1000, filled with 0’s
wins <- rep ( 0, 1000 )
for ( i in 1:1000 ) {
d <- sample ( 1:6, 2, replace=T )
if ( sum(d) == 7 || sum(d) == 11 ) wins[i] <- 1
}sum ( wins ) # print the number of wins



More information about the R-SIG-Finance mailing list