I would do it like this: library(TeachingDemos) tmp <- dice(10000, 2) with(tmp, c(sum(Red==Green),mean(Red==Green)) ) plot(head(tmp,28))
-- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Lemarian WallaceIII > Sent: Monday, October 04, 2010 10:14 PM > To: r-help@r-project.org > Subject: [R] R-help > > Im trying to simulate the rolling of a pair of dice > > this is my function: > #function to simulate tosses of a pair of dice > #from the simulation, the program returns the empirical probability of > #observing a double > count <- 0 > for(j in 1:sim){#begin loop > die1 <- sample(1:6,1) > print(die1) > die2 <- sample(1:6,1) > print(die2) > count <- ifelse(die1 == die2, count + 1, count) > }#end loop > emprob <- count/sim > return(count,emprob) > } #end program > > > these are the errors that keep coming up: > Error in 1:sim : 'sim' is missing > > > How do I correct this? > > > > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.