State Farm interview question

Solve the following r code error.