-2

I have file 1 with attributes like (706 attributes)

Matchid TeamName    Opp_TeamName    TeamRank    Opp_TeamRank    Team_Top10RankingBatsman
1   New Zealand      Bangladesh       1             10                   2
2   New Zealand        India          1             2                    2
3   India             England         2             5                    1
4   Australia        England          6             5                    1

and file 2 with attributes (706 attributes)

id  actual  predicted   error
3         79    206.828     127.828
1         90    182.522     92.522
2         101   193.486     92.486
4         89    174.889     85.889

I want to match "Matchid and id" of both files and add file2 attributes in file1 so that the final result is

Matchid TeamName    Opp_TeamName    TeamRank    Opp_TeamRank    Team_Top10RankingBatsman    id       actual  predicted   error
1   New Zealand      Bangladesh       1             10                   2                   1         90    182.522     92.522
2   New Zealand        India          1             2                    2                    2        101   193.486     92.486

3   India             England         2             5                    1                   3        79    206.828     127.828
4   Australia        England          6             5                    1                  4         89    174.889     85.889

so far I have tried tried simple merge function and it didn't work, how can I achieve my task?

rafa.pereira
  • 13,251
  • 6
  • 71
  • 109
melissa
  • 375
  • 1
  • 8
  • 20
  • `merge` should work (http://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-left-right). You can also use the `join` functions from the `dplyr` package. – Alex Jun 17 '16 at 20:16
  • Why didn't `merge` work? Can you provide your code? If you're more familiar with SQL you can use `sqldf`. – Hack-R Jun 17 '16 at 20:16

2 Answers2

1
merge(file1,file2,by.x="Matchid",by.y="id")

Maybe this way?

Rockbar
  • 1,081
  • 1
  • 20
  • 31
0

The dplyr way:

library(dplyr)

joined <- inner_join(file_1, file_2, by = c("Matchid" = "id"))
danh
  • 618
  • 3
  • 7