0

I would like to copy multiple columns from one data.frame to another data.frame but the matching variable has different text for the same values in each data.frame.

Suppose I have two data.frames df1 (contains 208 rows) and df2 (contains 351 rows).

Portion of df1

       Team   rank_A   fivey_rank_A
     Kansas        1              4
        UNC        5             12
    K-State       90             65
St. Bonnies       30             93

Portion of df2

           Team   rank_B   fivey_rank_B
 North Carolina        2              8
         Kansas        4            2.5
          Texas       30             21
        Florida       33             44
     Kansas St.       54             35
St. Bonaventure       84           80.5

I would like to copy df2$rank_B and df2$fivey_rank_B into df1 but only for the matching rows (an inner join).

As you can see the problem is that the text for values in the matching variable Team are not always the same text; even though they represent the same value.

What I would like df1 to look like after copying rows from df2

       Team   rank_A   fivey_rank_A   rank_B   fivey_rank_B
     Kansas        1              4        4            2.5
        UNC        5             12        2              8
    K-State       90             65       54             35
St. Bonnies       30             93       84           80.5

I am not sure how to do this in R, but I was thinking maybe I would use the letters in the teamnames and the values of rank_B, rank_A, fivey_rank_A, and fivey_rank_B to predict which rows in df2 match with df1.

Any help will be appreciated. Please let me know if further information is needed.

Dre
  • 713
  • 1
  • 8
  • 27
  • could you please post the command that you used for it. – Dinesh Apr 04 '16 at 04:59
  • 1
    Might be useful reading here : [merging-two-data-frames-using-fuzzy-approximate-string-matching-in-r](http://stackoverflow.com/questions/2231993/merging-two-data-frames-using-fuzzy-approximate-string-matching-in-r) and in the subsequently linked q/a's. – thelatemail Apr 04 '16 at 05:09
  • @AlphaBetaGamma Correct. I am copying from a large data.frame to a small data.frame. – Dre Apr 04 '16 at 05:37

0 Answers0