In advance, thank you!
I'm pretty new to R so please don't judge too much
I've written a loop that is similar to a MonteCarlo simulation, my problem is that it takes 6 minutes for 100.000 loops, and 4 hours for 500.000 loops. but i don't understand why it is so ineffective.
Is there a better way to do this and obtain the same result?
The reason your code ran so slowly is that (a) it wasn't vectorised (i.e. the loop isn't required) and (b) the results dataframe was being expanded one row at a time, rather than its dimensions being defined upfront, which is very slow.
Thank you for your input, however with this set-up the Events would not be happening independent.
For every n one random number is generated, so if that number is high, no events will happen, but if it is very low, then all will happen at once.
While I would want each event to be individual
I think i have solved it by changing your code to