Skip to content

Instantly share code, notes, and snippets.

@BioSciEconomist
Created November 6, 2016 17:13
Show Gist options
  • Save BioSciEconomist/d2530aa12e94988fefcef6629fae9be0 to your computer and use it in GitHub Desktop.
Save BioSciEconomist/d2530aa12e94988fefcef6629fae9be0 to your computer and use it in GitHub Desktop.
Merging multiple date frames in R
### r code to support: http://econometricsense.blogspot.com/2011/01/merging-multiple-data-frames-in-r.html
# read all Y2000 csv files
filenames <- list.files(path="/Users/wkuuser/Desktop/R Data Sets/TRADE_DATA/TempData00", full.names=TRUE)
import.list <- llply(filenames, read.csv)
# left join all Y2000 csv files
AllData00 <- Reduce(function(x, y) merge(x, y, all=FALSE,by.x="Reporting.Countries.Partner.Countries",by.y="Reporting.Countries.Partner.Countries",all.x =TRUE, all.y =FALSE),import.list,accumulate=F)
dim(AllData00) # n = 211 211
# rename common key variable to something less awkward and change World to World00
AllData00 <- rename(AllData00, c(Reporting.Countries.Partner.Countries="Partner", World = "World00"))
names(AllData00) # list all variable names
# keep only the partner name variable and total world trade
AllData00 <-AllData00[c("Partner","World00")]
dim(AllData00) # data dimensions
names(AllData00) # variable names
fix(AllData00) # view in data editor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment