I am attempting to merge many (~40) dataframes (i.e. pH, fieldpH, AlkT, …) into one dataframe based on a unique identifier (row ID) “SampleID”, however, when I attempt to merge these files using the script below the file reaches 75MB and crashes. The final, combined file will be large, but 75MB seems a little extreme.
I’m not sure if I am compounding the files and accidentally making the file size larger?
Any help or insight as to how to fix this problem or a suggestion of a better way to merge numerous dataframes based on row ID would be greatly appreciated!
Disclaimer: that I am definitely a beginner with R and coding in general.
## Subset original file ##
pH<-subset(data, VARIABLE_TRIM == "PH")
pH<-pH[c("SampleID", "MONTH", "YEAR", "FLAG", "VALUE_CONV")]
names(pH)[5]<-"pH"
fieldpH<-subset(data, VARIABLE_TRIM == "FIELD PH")
fieldpH<-fieldpH[c("SampleID", "FLAG", "VALUE_CONV")]
names(fieldpH)[3]<-"Field pH"
## Merge dataframes ##
fulldata <- Reduce(function(x, y) merge(x, y, by = "SampleID",
all.x = TRUE, all.y = TRUE),
list(pH, fieldpH, AlkT, Hard, Hard2, DO, DOC, TOC, Spec,
SpecField, TempField, Temp, SbT, SbD, AsT, AsD, CdT,
CdD, CrT))