Type & Coercion Errors
Argument not numeric or logical
Matches: argument is not numeric or logical
WHAT THIS ERROR MEANS
A function that expects numbers (like mean, sum, sd) received non-numeric data such as character strings.
HOW TO FIX IT
1. Check the column type with class(your_data$column).
2. Convert to numeric: as.numeric(your_data$column).
3. Make sure you're referencing the correct column.
CODE EXAMPLES
BAD — THIS CAUSES THE ERROR
mean(c("1", "2", "3")) # character vectorGOOD — CORRECT APPROACH
mean(as.numeric(c("1", "2", "3")))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...
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...