If I have an operation including randomness (lets call it operation_with_randomness(number)
) and I want it to run x times
> b <- rep(operation_with_randomness(number), x)
I get
> b
1.5472491 1.5472491 1.5472491 1.5472491 1.5472491 1.5472491 ...
Is there any smart way (e.g. not a loop structure) to run the operation_with_randomness(number)
each time to get a b vector which holds values from x separate runs?
Probably replicate() will meet:
> z <- replicate(10, runif(1))
> z
[1] 0.762778299 0.541601960 0.654238258 0.026323048 0.532011084 0.905059722 0.328891040 0.297307167 0.004157573 0.507231966
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With