I am exporting data to a MySQL database from R using the RMySQL
package. A big problem I am facing is duplicates: I have too many entries with same values. The system automatically produces the results and inserts the dataframe into the database.
Current Table in DB:
Name Balance
Bob 100
Ted 150
Carl 130
I also have a data frame (df
) in R reflecting changed balances:
> df
Name Balance
[1] Bob 100
[2] Ted 150
[3] Bill 50
Data to be inserted in DB:
Name Balance
Bill 50
Now after insertion, Table should look like this:
Name Balance
Bob 100
Ted 100
Carl 130
Bill 50
But my dbwrite produces this:
Name Balance
Bob 100
Ted 100
Carl 130
Bob 100
Ted 150
Bill 50
I am using this code:
dbWriteTable(con, "DB Table name", rbind(Dataframe), row.names=FALSE,append=TRUE)
Is there any way to check for existing ones and update the table with only new ones using RMYSQL in R.