For the question mentioned in the subject, I have used a slightly different approach in comparison to the one produced in the ER. The maximum possible marks for the same question is 6. Do let me know the score that I would obtain using my method. Answer in the Examiner's Report: Median<- rep(0,5) Mean<- rep(0,5) Var<- rep(0,5) for(i in 1:5) { Median<- median(salary.current[job.type==i] ) Mean<- mean(salary.current[job.type ==i] ) Var<- var(salary.current[job.type ==i] ) } ## Median # 9.180 9.285 9.410 10.160 10.030 ## Mean # 9.168571 9.280333 9.440000 10.101333 10.119167 ## Var # 0.07471261 0.02906540 0.00320000 0.03128381 0.05988106 My Solution: I have individually figured out the values and then copy-pasted the same. In addition, I also wanted to understand when and in what situations am I supposed to use the FOR loop. Thanks & Regards.
I'm assuming you just calculated each of them the long-winded way and got the same answers. In which case you would have got the marks - it just would have taken you a lot longer. Hence, a loop would have saved you time. That's the point of loops - to do the same task repeatedly. However, the only places where you have to use a loop are clearly indicated in the Core Reading (eg bootstrapping).