Replace empty values with value from other column in a dataframe
Try ifelse
:
df$baglocatie <- ifelse(df$baglocatie == "", df$knmilocatie, df$baglocatie)
You need to index also the replacing column:
df[ df$baglocatie == "", "baglocatie" ] <- df[ df$baglocatie == "", "knmilocatie" ]
Or you can use a support vector:
empty <- df$baglocatie == ""
df$baglocatie[empty] <- df$knmilocatie[empty]