0

I have tried to replicate other stack answers regarding similar questions but have not had much success. I am trying to combine 3 CSV files in R regarding the world cup. All 3 CSV files have a similar column named "Country". My goal is to merge all 3 csv files into one singular dataframe and then back into a csv file. I want each country value within G.csv to have the respective values from GG.csv and LL.csv. The following is what columns each csv file contains.

G.csv has Country and Group # (Char, Int)

GG.csv has Country,# of Goals, and # of Games (Char, Int, Int)

LL.csv has Country, Latitude, and Longitude (Char, Int, Int)

This is my code thus far in my attempt to merge 2 of the files together. The result is a merged file with 0 observations. In other attempts, I got a merged file with duplicated rows (USA would show up twice, one having values from G.csv and the other USA having values from GG.csv)

G <- read.csv("G.csv", fileEncoding="UTF-8-BOM")
GG <- read.csv("GG.csv", fileEncoding="UTF-8-BOM")
LL <- read.csv("LL.csv", fileEncoding="UTF-8-BOM")

M <- merge(GG, G, by = "Country")

Any help (no matter how basic like libraries/packages/etc) would be appreciated! It's been a minute since Ive used R but I feel like I shouldnt be running into such issues regarding a straightforward merge function.

Here is an image of my CSV files CSV side by sides

Adr0
  • 1
  • 1
  • Hi! Welcome to StackOverflow. Your code seems to be what you are looking for. Did you ensure that 'Country' variable was written in the same way in every file? Can you rewrite your message including `head(G)` and `head(GG)` to see how data looks like? – R18 Jul 21 '22 at 05:34
  • Hi, sorry not really sure what you mean by the head(G) functions, but I added an image if that helps. Also, thank you for the welcome! – Adr0 Jul 21 '22 at 05:46

0 Answers0