question 4 to 5. q5 not finished. should use data.table instead of data.frame