I hope this question is clear and feasible. I have many csv files labelled with a simple numeric ID (e.g., 1.csv, 2.csv, 3.csv, etc.). Another csv file contains the actual data like below
ID Site Location Block
1 L1 1 a
2 L2 2 b
3 etc
My question is how to link the ID in the data file to rename the csv files. The output I would ideally like to have is L11a.csv, L22b.csv, etc. I think I need to concatenate each row observation's Site, Location, and Block into another column and then use that column as the filename for the write.table function?
I searched SO and this question is similar except in the reverse direction: When importing CSV into R how to generate column with name of the CSV?
Many thanks for your assistance. This would save me hours in renaming files!
I have simulated your scenario with four csv files and the data in a file called
info.txt
with this content:For this setup the following code will achieve what you want if my understanding is correct:
(Building on @joran's comments)
Here's another option: