[R] R-help

Greg Snow Greg.Snow at imail.org
Tue Oct 5 18:06:37 CEST 2010


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.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Lemarian WallaceIII
> Sent: Monday, October 04, 2010 10:14 PM
> To: r-help at 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]]



More information about the R-help mailing list