Glam Prestige Journal

Bright entertainment trends with youth appeal.

$\begingroup$

I'm running this simulation where you roll a die in R and record the result. Part of the code I got from my professor says cumulative.sums = cumsum(roll == 1)

I'm not exactly sure what this code means. and here's the result I got. trial.num roll.result cumulative.sums proportion [1,] 1 6 0 0.0000000 [2,] 2 3 0 0.0000000 [3,] 3 1 1 0.3333333 [4,] 4 3 1 0.2500000 [5,] 5 1 2 0.4000000 [6,] 6 3 2 0.3333333

$\endgroup$ 1

1 Answer

$\begingroup$

You can always google:

And this function is shown very clearly by its name - cumulative sum: It is summing all the elements in a vector, the argument of this function.

In your example the vector "roll==1" is extracting the indicator of each roll results equal to 1 as a vector, so essentially you are counting the number of 1's in the vector "roll".

$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy