In this example dataframe:
The object is to replace the <NA>
values with the “ReplacementRate” value from this dataframe:
What is the best way to do this? (I prefer to not use a join.)
For the first attempt, I used the impute_na
function with the following statement
impute_na(OriginalRate, type = "value", val = Replacement$ReplacementRate[Replacement$RateType==RateType])
And received this error:
'2. Create Calculation (Mutate)' step has an error. Error : Problem with `mutate()` input `OriginalRate`. x Can't recycle `..1` (size 10) to match `..2` (size 0). i Input `OriginalRate` is `impute_na(...)`.
For the second attempt, I tried the mutate
function:
with the following statement:
if_else(is.na(OriginalRate), Replacement$ReplacementRate[Replacement$RateType==RateType],OriginalRate)
And received this error:
'2. Create Calculation (Mutate)' step has an error. Error : Problem with `mutate()` input `OriginalRate`. x `true` must be length 10 (length of `condition`) or one, not 0. i Input `OriginalRate` is `if_else(...)`.
I suspect this has something to do with the scalar vs vector issue that @sugiaki nicely explained previously here:
but I still have no idea how to move past this!
Also, here another post that others might find helpful, where @Kei_Saito describes how to access the value in another dataframe:
Please help. Thanks in advance.
`