Please can someone help, when I am running this code. I am getting an error message which says
Error in 1:N : NA/NaN argument
In addition: Warning message:
In 1:N : numerical expression has 5 elements: only the first used
birthday_part02 = function(N) {
# Initialise counter
count = 0
# Loop by the number of iteration defined by the value N
for (i in 1:N) {
# Generate a sample of birthdays
birthdays = sample(1:365, 10, replace = T)
if (length(unique(birthdays)) < 10) {
# If there duplicate birthday increase counter
count = count + 1
}
}
return(count / N)
# Return the proporation of duplicates
}
# Assign a vector of those numbers to N
N = c(10, 50, 100, 1000, 10000)
# A for loop that loops for a length of 5
prop_people = numeric(length = 5)
for (i in 1:N) {
prop_people[i] = birthday_part02(N[i])
}