Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # namespace gl
- gl <- new.env()
- # # of trials to run
- gl$trials <- 20000
- # profits (price minus costs) and their related probabilities
- gl$entreeProfit <- c(9,7.5,5.5,4)
- gl$entreeProbability <- c(0.25,0.35,0.3,0.1)
- # empty vector for trial data
- gl$results <- c()
- # iterate through trials and fill data frame row by row
- for(i in 1:gl$trials){
- profit <- sample(gl$entreeProfit,1,TRUE,gl$entreeProbability)
- meals <- rnorm(1,3000,1000)
- labor <- runif(1,5040,6860)
- gl$results <- rbind(gl$results, profit * meals - labor - 3995)
- }
- # tidy up global environment
- remove(profit,meals,labor,i)
- summary(gl$results)
- hist(gl$results)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement