Write a function top10()
that returns the 10 most common values in a (sorted) vector, along with their counts. Apply your function to the column Father
in the hafu
dataset and store your results in an object called Father_top10
and do the same for the column Mother
and store these results in Mother_top10
.
Hint: Be aware of missing values which should also be returned in the counts!
(from: Cotton, 2013, Learning R, O’Reilly)