Type & Coercion Errors
Vector length not a multiple
Matches: longer object length is not a multiple of shorter object length
WHAT THIS ERROR MEANS
You're operating on two vectors where the longer one's length is not a clean multiple of the shorter one. R will still recycle, but the result may not be what you intended.
HOW TO FIX IT
1. Check vector lengths with length().
2. Make sure vectors are the same length for element-wise operations.
3. Explicitly recycle with rep() if intentional.
CODE EXAMPLES
BAD — THIS CAUSES THE ERROR
c(1, 2, 3) + c(10, 20) # 3 is not a multiple of 2
GOOD — CORRECT APPROACH
c(1, 2, 3) + c(10, 20, 30) # same length
Still stuck?
Paste your code in RChat and the AI will fix this error in context.
RELATED TYPE & COERCION ERRORS
Non-numeric argument to operator You tried to do math (like +, -, *, /) on something that isn't a number, such as...
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...