Get Started →
Type & Coercion Errors

Replacement length mismatch

Matches: replacement has (\d+) rows?, data has (\d+)

WHAT THIS ERROR MEANS

You tried to assign a value to a column or vector, but the length of the new value doesn't match the existing data.

HOW TO FIX IT

1. Check the length of both sides of the assignment.

2. Use rep() or recycle properly.

3. Make sure your filter conditions are correct.

CODE EXAMPLES

BAD — THIS CAUSES THE ERROR
df$new_col <- c(1, 2, 3)  # but df has 5 rows
GOOD — CORRECT APPROACH
df$new_col <- c(1, 2, 3, 4, 5)  # match row count

Still stuck?

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

Try RChat Free →

RELATED TYPE & COERCION ERRORS