How to Solve R Error: Unexpected else

This error occurs if you put the else statement on a new line after an if statement. R interprets the if statement as complete and does not expect an else. You can solve this error by enclosing the entire if/else statement in braces/curly brackets {} or put the else...