Subscript & Indexing Errors
$ operator on atomic vector
Matches: \$ operator is invalid for atomic vectors
WHAT THIS ERROR MEANS
You used $ to access a named element, but the object is a simple vector, not a list or data frame.
HOW TO FIX IT
1. Check what type your object is with class().
2. Use [ ] indexing for vectors instead of $.
3. If you expected a data frame, check how the object was created.
CODE EXAMPLES
BAD — THIS CAUSES THE ERROR
x <- c(a = 1, b = 2) x$a
GOOD — CORRECT APPROACH
x <- c(a = 1, b = 2) x["a"]
Still stuck?
Paste your code in RChat and the AI will fix this error in context.
RELATED SUBSCRIPT & INDEXING ERRORS
Subscript out of bounds You tried to access an element at a position that doesn't exist — like asking fo...
Undefined columns selected You tried to select a column that doesn't exist in your data frame, usually due ...
Incorrect number of dimensions You used multi-dimensional indexing (like [row, col]) on an object that doesn't ...
Recursive indexing failed You tried to access a nested element in a list using [[ ]] but the path doesn't ...