b_day <- as.Date('2000-05-12')
n_years <- 100

b_day_vec <- seq(b_day, b_day + n_years*365, by = '1 year')

w_days <- weekdays(b_day_vec)

n_weekend <- sum(w_days %in% c('Saturday', 'Sunday'))

# solution
my_sol <- n_weekend
my_answers <- make_random_answers(my_sol)

#check_answers(my_answers)

Question

Assuming that a person born on r b_day will live for r n_years years, what is the number of birthday days that will fall on a weekend (Saturday or Sunday)? Tip: use operator %in% to check for a multiple condition in a vector.

exams::answerlist(my_answers, markup = "markdown")

Solution


Meta-information

extype: num exsolution: r my_sol exname: "dates" exshuffle: TRUE



msperlin/afedR documentation built on Sept. 11, 2022, 9:49 a.m.