Alan T.

asked • 09/13/21

Questions about R Programming

I want to know how to write the R code for these:




Consider a game of throwing 2 fair dice at the same time. You win $6 if the total of these 2 dice is greater than or equal to 10; or you lose $1 if the total is less than 10. You start with $50 in your pocket and you stop gambling if you lose all your money or you have $100 or more in your pocket. The following points will guide through the simulation of this game step by step: 


  1. Use the digits "1234" as the initial seed, generate 2000 random numbers that mimic the throw of a fair dice as save them to d. 
  2. Transform d into a 1000x2 matrix and compute the row total as t. 
  3. Compute a reward vector w from t; that is, w=-1 if t<10 or w=6 if t>=10. 
  4. Compute a vector x representing the money in your pocket. Plot x with type=”l” and add two horizontal lines at y=0 and y=100. 
  5. Write R commands to find out the first time that x=0 or x>=100 respectively.


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.