Get Started →
Subscript & Indexing Errors

Incorrect number of dimensions

Matches: incorrect number of dimensions

WHAT THIS ERROR MEANS

You used multi-dimensional indexing (like [row, col]) on an object that doesn't have that many dimensions.

HOW TO FIX IT

1. Check dimensions with dim(), nrow(), ncol().

2. Use single brackets for vectors: x[i] not x[i, j].

3. Convert to matrix or data frame if needed.

CODE EXAMPLES

BAD — THIS CAUSES THE ERROR
x <- 1:10
x[1, 2]  # x is a vector, not a matrix
GOOD — CORRECT APPROACH
x <- 1:10
x[1]  # single index for vectors

Still stuck?

Paste your code in RChat and the AI will fix this error in context.

Try RChat Free →

RELATED SUBSCRIPT & INDEXING ERRORS