Get Started →
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.

Try RChat Free →

RELATED SUBSCRIPT & INDEXING ERRORS