# Merging multiple files: # Merge the two tables based on common id field: # master <- merge(master, target, by.x="id", by.y="id", all.x=T) # x is the master dataframe ("master") and y is the dataframe being merged ("target") # Example (merging two SNP genotype files to the master 1KG_HLA file): frame1 <- read.csv(file.choose()) # select the master file (hlamaster.csv) frame2 <- read.csv(file.choose()) # select SNP1 genotype file (hlasnp1.csv) frame3 <- read.csv(file.choose()) # select SNP2 genotype file (hlasnp2.csv) master <- merge(frame1, frame2, by.x = "id", by.y = "id", all = TRUE) master1kg <- merge(master, frame3, by.x = "id", by.y = "id", all = TRUE) head (master1kg, 1) # to confirm that the merging is successful write.csv(master1kg, "master.csv") # exports the merged file as a CSV file to working directory # SEE http://manuals.bioinformatics.ucr.edu/home/R_BioCondManual for more # search "merge(frame1, frame2, by.x = "frame1col_name", by.y = "frame2col_name", all = T)"