[R] R-help

Joshua Wiley jwiley.psych at gmail.com
Tue Oct 5 08:30:21 CEST 2010


On Mon, Oct 4, 2010 at 9:13 PM, Lemarian WallaceIII <tott_03 at yahoo.com> wrote:
> 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

You need to define an object called 'sim', otherwise you are telling R
to go look up the value of a non-existent variable.  Does your
function have a first part?  All I am seeing is the body and the end.

Josh

>
>
> How do I correct this?
>
>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at 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.
>
>

-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list