finished r code for quiz