The answer for the first question should be D, correct?
I think the answer provided in the document is wrong. B is wrong, because it only prints the two males in the first 5 observations. We must sort the data according to sex (descending) so that all males come before females. Then we print the first 5 observations; all will be male.