In one column of my dataframe I have some empty cells. The data looks like this:
yymmdd lat lon mag depth knmilocatie baglocatie tijd
19861226 52.
Or you can use a support vector:
empty <- df$baglocatie == ""
df$baglocatie[empty] <- df$knmilocatie[empty]
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" ]