For class we are beginning to work with for() loops and understanding simulations. We have two questions that are throwing me off. Here's the code that initiates the series of questions:
set.seed(25)#so you guys can follow me
b = rbinom(100,1,.6)
From here we need to write a line of code using sum() that will pull out ANY two consecutive elements and sum them.
Then, we need to use this as a base to write a loop that follows this psuedo-code:
initialize element number i = 1;
while the sum of elements i and i +1 is not zero do
i = i +1;
end
print i +1
The idea is we need to summarize from this random vector the number of elements until 2 consecutive elements = 0. That's our stopping point. Then we're going to simulate this 1000 times in a for() loop to get a distribution of elements before the double 00's.
I can pull out elements manually and run the for() loop but I don't get how to automate it. I'd appreciate some help getting my mind straight on how to do this. Thanks
Aucun commentaire:
Enregistrer un commentaire