r - How can I merge two dataframes if two cols have to be the same? -


this question has answer here:

i have 2 data frames. example df1 looks like:

name month number        1.h  1      8 2.h  2      7   3.h  3      6  4.a  1      9 5.a  2      10 6.a  3      11 

and df2 looks like:

name month index       1.h    1      3 2.h    2      2   3.h    3      1 4.a    1      3  5.a    2      5 6.a    3      9 

and want merge following df:

  name month number index   1.h  1    8       3   2.h  2    7       2   3.h  3    6       1   4.a  1    9       3   5.a  2    10      5   6.a  3    11      9 

how can merge 2 df's df?

i have tried merge function by.x , by.y allows merging 1 column, want second column.

you can merge on more 1 column @ time:

merge(df1, df2, = c('name', 'month')) 

in fact, should default, default value of by intersect(names(df1), names(df2)).


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -