This is obviously about as far from a finance question as they come.

Please do read the posting guidelines before asking a question, and
additionally
try to read the manual before asking your next question.

The code works perfectly if you took a moment to understand R's syntax.

It should read:

> 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)
[1] 229

obviously (or not) your answer for sum(wins) will be different.  The problem
is in the closing brace to the 'for' statement.

FYI
>  is the default prompt in R
+ is the line continuation character.

Hope this helps.

Jeff
On 10/30/06, jk <alte@comcast.net> wrote:
>
> 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
>
> _______________________________________________
> R-SIG-Finance@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>

	[[alternative HTML version deleted]]

