Type & Coercion Errors
Non-numeric argument to operator
Matches: non-numeric argument to binary operator
WHAT THIS ERROR MEANS
You tried to do math (like +, -, *, /) on something that isn't a number, such as a character string or factor.
HOW TO FIX IT
1. Check the types of your variables with class() or str().
2. Convert to numeric with as.numeric() if appropriate.
3. Make sure you're referencing the right column.
CODE EXAMPLES
BAD — THIS CAUSES THE ERROR
"10" + 5 # "10" is a string, not a number
GOOD — CORRECT APPROACH
as.numeric("10") + 5Still stuck?
Paste your code in RChat and the AI will fix this error in context.
RELATED TYPE & COERCION ERRORS
Argument not numeric or logical A function that expects numbers (like mean, sum, sd) received non-numeric data s...
Cannot coerce type R tried to convert one data type to another but failed because the conversion is...
Invalid argument type An argument you passed to a function is the wrong type. The function expected on...
Replacement length mismatch You tried to assign a value to a column or vector, but the length of the new val...