I have a dataframe combi including two variables DT and OD.
I have a few missing values NA in both DT and OD but not necessary the same record.
I then try to rep
Because the number of items to replace is not a multiple of replacement length. The number of items to replace is the number of rows where is.na(combi$DT) & !is.na(combi$OD)
which is less than the number of rows in combi
(and thus the length of the replacement).
You should use ifelse
:
combi$DT <- ifelse(is.na(combi$DT) & !is.na(combi$OD), combi$OD, combi$DT)
N.B. the & !is.na(combi$OD)
is redundant: if both are NA
, the replacement will be NA
. So you can just use
combi$DT <- ifelse(is.na(combi$DT), combi$OD, combi$DT)