5.10 For loops
Instead of drawing multiple times from the same distribution, we can write a for loop to repeatedly generate and update the number of individuals with the A
allele.
A for loop allows you to run some code X number of times. For example:
for (i in 1:3) {
print(i)
}
## [1] 1
## [1] 2
## [1] 3
This for loop goes through all the values between 1 and 3, and prints each of them out.
Modify the for loop to instead run our rbinom
command.
for (i in 1:3) {
print(rbinom(n = 1, size = 100, prob = 0.5) / 100)
}
## [1] 0.49
## [1] 0.45
## [1] 0.43