This is an associated question to rename filename with a data column.
I have files with duplicate names and a data file with additional rows that do not have separate csv files for this analysis. For example: the format of my data file is this:
ID Cluster Block Site Depth
1 A1 1 1 a
2 A1 1 1 b
3 A1 1 1 c
4 A1 1 1 d
5 A1 2 1 a
6 A1 2 1 b
7 A1 2 1 c
...
600 M1 10 1 a
601 M1 10 1 b
602 M1 10 1 c
603 M1 10 1 d
The sites and depth repeats in sets of 4. I have a list of csv files for only a and b depths, which mean I only have files with IDs for 1,2,4,5,9,10 etc. These files are labelled slightly differently and have replicates. For example, files in my folder are like this:
1p.csv
1pr.csv
2p.csv
2pr.csv
5p.csv
5pr.csv
6p.csv
6pr.csv
My desired function is to combine data in selected columns for each of the IDs as a file name for corresponding csv files. The csv files are in sets of 2 with a replicate for each file. I am having difficulty adapting the linked question rename filename with a data column because of my limited scripting knowledge and because of the different 'from' and 'to' lengths, which is not allowed for file.rename (). The error message I get is "Error in file.rename(x, y) : 'from' and 'to' are of different lengths."
Thank you so much for your help and suggestions.