I'd prefer to do the following in R, but am open to (easy to learn) other solutions.
I have multiple (lets say 99) tab-delimited files (let's call them S1.txt through S99.txt) with tables, all with the exact same format. Each table is ~2,000,000 cols by 5 rows. Here's a toy example:
ID Chr Position DP1 DP2
A1 1 123 1.5 2.0
A2 1 124 1.4 0.3
ID by definition is unique and always in the same order, Chr and Pos are always in the same order. The only things different in each input file are DP1 column and DP2 column. The output table I'd like to be "collated", I think is the word. Here's an example of the output if there were ONLY 3 Sample input files.
ID Chr Position S1.DP1 S1.DP2 S2.DP1 S2.DP2 S3.DP1 S3.DP2
A1 1 123 1.5 2.0 1.2 2.0 1.5 2.1
A2 1 124 1.4 0.3 1.0 0.5 0.5 0.05
Notice that each input file has a new column created for DP1 and DP2. ALSO, the name of the columns is informative (tells me which input file it came from & which datapoint - DP).
I've found questions for when the columns are different: R: merging a lot of data.frames I'm also aware of merge, although I feel like you end up with strange column names: How to join (merge) data frames (inner, outer, left, right)?
My other solution has been to initialize a dataframe and then load each file and add the data points, but this would use a loop and be incredibly slow and horrible. So, I need a more elegant solution. Thank you for your help.