Get Started →
Type & Coercion Errors

Replacement length not a multiple

Matches: number of items to replace is not a multiple

WHAT THIS ERROR MEANS

The number of values you're assigning doesn't evenly divide into the number of positions being replaced.

HOW TO FIX IT

1. Check the length of the replacement vector.

2. Make sure it matches the target length.

3. Use rep() to repeat values to the right length.

CODE EXAMPLES

BAD — THIS CAUSES THE ERROR
x <- 1:10
x[1:6] <- c(0, 0)  # 2 doesn't divide into 6
GOOD — CORRECT APPROACH
x <- 1:10
x[1:6] <- rep(0, 6)  # correct length

Still stuck?

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

Try RChat Free →

RELATED TYPE & COERCION ERRORS