I\'m trying to figure out how to use merge()
to update a database.
Here is an example. Take for example the data frame foo
Another approach could be:
Remove the NAs from the first data fram
Use rbind to append the data instead of using merge:
These are the original two data frames:
foo <- data.frame(index=c('a', 'b', 'c', 'd'), value=c(100, 101, NA, NA))
bar <- data.frame(index=c('c', 'd'), value=c(200, 201))
(1) Use the negation of is.na to remove the NAs:
foo_new <- foo[!is.na(foo$value),]
(2) Bind the data frames and you'll get the answer you were looking for
new_df <- rbind(foo_new,bar)
new_df
index value
1 a 100
2 b 101
3 c 200
4 d 201