Subscript & Indexing Errors
Subscript out of bounds
Matches: subscript out of bounds
WHAT THIS ERROR MEANS
You tried to access an element at a position that doesn't exist — like asking for the 10th element of a 5-element vector.
HOW TO FIX IT
1. Check the length of your object with length() or nrow()/ncol().
2. Make sure your index is within the valid range.
3. Remember R is 1-indexed (first element is [1], not [0]).
CODE EXAMPLES
BAD — THIS CAUSES THE ERROR
x <- c(1, 2, 3) x[5] # only 3 elements
GOOD — CORRECT APPROACH
x <- c(1, 2, 3) x[3] # valid index
Still stuck?
Paste your code in RChat and the AI will fix this error in context.
RELATED SUBSCRIPT & INDEXING ERRORS
Undefined columns selected You tried to select a column that doesn't exist in your data frame, usually due ...
$ operator on atomic vector You used $ to access a named element, but the object is a simple vector, not a l...
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 ...