-2

I have a dataframe df1 , which consists of columns from Var1 to Var10. Now I have taken a subset of columns as a dataframe df2 from Var5 to Var9, performed some operations and now I have to overwrite df1 with columns from df2.

I want to merge df2 ie var5 to var10 to df1(which also has var5 to var9 columns).

I tried below code:

merge(df1,df2,by.x = "",y="")

Ideally I have a lot of columns, specifying columns with comma isn't a great way

David Arenburg
  • 91,361
  • 17
  • 137
  • 196
  • It would be great if could provide a reproducible exemple of your problem (with sham data if needed). You can use `dput(mydata)` e.g or more here: [how-to-make-a-great-r-reproducible-example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – cbo Jun 24 '19 at 11:39

1 Answers1

0

Using ?merge it appears you don't need the extra by.x or y arguments. Moreover by uses by default common variable names between data.frames. Thus, provided you don't have duplicates subsetting by Var5:Var9 on the whole data set you could do :

merge(x = df1, y = df2)
cbo
  • 1,664
  • 1
  • 12
  • 27