number of items to replace is not a multiple of replacement length

Hi @shasank! Welcome!

Let's take it piece by piece...

claims$newprocall <-claims$newproc.x

This line replaces the entire column newprocall (in the claims data frame) with the values in a different column of the claims data frame (newproc.x).


This selects all the values in the newprocall column (in the claims data frame) that have the same index number as the NA values in the newproc.x column (in the same claims data frame).


This selects every element of the column newproc.y, which comes from a different data frame (reducedclaims, rather than claims).

First, I'm not sure this code is doing what you want? Do you want to replace the NAs in both claims$newprocall and claims$newproc.x with values pulled from some other column? How do you know which are the right values to pick from the other column, if the other column is in a totally different data frame?

Second, the error message: this is telling you that the thing on the left-hand side of the arrow (the values in claims$newprocall that have the same index numbers as the NA values in claims$newproc.x) is a different length from the thing on the right-hand side of the arrow (all of the values in reducedclaims$newproc.y). If the right-hand side is a multiple of the left-hand side, then R will try to recycle it to match the left-hand side length. Otherwise, R doesn't know how to replace a vector of one length with a vector of a different length.

I know that's all a bit general — it's hard to be more specific without a reproducible example to work with. A small reproducible example would also help me understand what it is you are trying to do. For tips on how to create an example that will help people help you more, start here: FAQ: Tips for writing R-related questions